Skip to content

Instantly share code, notes, and snippets.

@edussx
Created February 17, 2013 07:28
Show Gist options
  • Save edussx/4970544 to your computer and use it in GitHub Desktop.
Save edussx/4970544 to your computer and use it in GitHub Desktop.
CareerCup 1.3
//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