Created
July 5, 2015 02:16
-
-
Save luckypapa/e3befddbf93e19de06df to your computer and use it in GitHub Desktop.
Lecture Note solution
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
| // https://algospot.com/judge/problem/read/LECTURE | |
| // Time Complexity : O(nlogn) | |
| // Space Complexity : O(n) | |
| #include <string> | |
| #include <vector> | |
| #include <iostream> | |
| #include <algorithm> | |
| using namespace std; | |
| struct Comp { | |
| bool operator () (string i, string j) { return (i < j); } | |
| } comp; | |
| string sortedString(const string &str) { | |
| int length = str.length(); | |
| string sortedStr; | |
| if (length > 1000 || length%2 != 0) return sortedStr; | |
| vector<string> v; | |
| for (int i = 0; i < length; i += 2) { | |
| v.push_back(str.substr(i, 2)); | |
| } | |
| sort(v.begin(), v.end(), comp); | |
| for (vector<string>::iterator it = v.begin(); it != v.end(); it++) { | |
| sortedStr += *it; | |
| } | |
| return sortedStr; | |
| } | |
| int main(void) { | |
| int testCount, i; | |
| string str; | |
| vector<string> v; | |
| cin >> testCount; | |
| for (i = 0; i < testCount; i++) { | |
| cin >> str; | |
| v.push_back(sortedString(str)); | |
| } | |
| for (vector<string>::iterator it = v.begin(); it != v.end(); it++) { | |
| cout << *it << endl; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment