Created
February 17, 2013 07:28
-
-
Save edussx/4970544 to your computer and use it in GitHub Desktop.
CareerCup 1.3
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
//CareerCup 1.3 | |
//by edussx | |
#include <string> | |
using std::string; | |
//sort a string, return the sorted string | |
//not an efficient sorting algorithm, though | |
string sort(const string& str) | |
{ | |
string str_return = str; | |
bool ifSwapped = true; | |
while (ifSwapped == true) | |
{ | |
ifSwapped = false; | |
for (int i = 0; i < str_return.size()-1; i++) | |
{ | |
if (str_return[i] < str_return[i+1]) | |
{ | |
char temp = str_return[i]; | |
str_return[i] = str_return[i+1]; | |
str_return[i+1] = temp; | |
ifSwapped = true; | |
} | |
} | |
} | |
return str_return; | |
} | |
//compare two sorted string | |
bool ifPermu(const string& s1, const string& s2) | |
{ | |
string s1_new = sort(s1); | |
string s2_new = sort(s2); | |
return s1_new == s2_new; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment