Last active
November 26, 2016 12:18
-
-
Save Parassharmaa/92da85ae782f5e4965137ae0d3571490 to your computer and use it in GitHub Desktop.
Cpp program to divide the string in equal parts and sort out the substrings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <cstdlib> | |
| #include <cstring> | |
| #include <vector> | |
| #include <algorithm> | |
| using namespace std; | |
| class str_op { | |
| string s; | |
| public: | |
| str_op(string str) { | |
| s = str; | |
| } | |
| str_op() { | |
| string st; | |
| cout<<"Input String: "; | |
| cin>>st; | |
| s = st; | |
| } | |
| vector<string> str_fun(); | |
| void str_print(vector<string>); | |
| }; | |
| int s_div(int nn) { | |
| int s=1; | |
| for (int i=2;i<nn;i++) { | |
| if(nn%i==0) { | |
| s=i; | |
| break; | |
| } | |
| } | |
| return s; | |
| } | |
| int main() { | |
| str_op s; | |
| vector<string> str_arr = s.str_fun(); | |
| s.str_print(str_arr); | |
| return 0; | |
| } | |
| vector<string> str_op::str_fun() { | |
| int n = s.length(); | |
| int mult = s_div(n); | |
| vector<string> s_arr; | |
| for (int i=0;i<n;i+=mult) { | |
| s_arr.push_back(s.substr(i,mult)); | |
| } | |
| sort(s_arr.begin(), s_arr.end()); | |
| return s_arr; | |
| } | |
| void str_op::str_print(vector<string> v) { | |
| for(vector<string>::const_iterator i = v.begin();i!=v.end();++i) { | |
| cout<<*i<<endl; | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment