#include #include #include "strutils.h" using namespace std; int max(string s) { int index = 0, comma, prevcomma = -1, number, max = INT_MIN; comma = s.find(","); while ( comma != string::npos ) { number = atoi(s.substr(prevcomma+1, comma)); if ( number > max ) { max = number; index = prevcomma+1; } prevcomma = comma; comma = s.find(",", prevcomma+1); } return index; } int main() { string current, s; int index, comma, length; cin >> s; while ( s.length() > 0 ) { index = max(s); comma = s.find(",", index); cout << s.substr(index, comma-index) << ","; current = s; if (index > 0) s = s.substr(0, index); else s = ""; if ( comma < current.length()-1 ) s += current.substr(comma + 1, current.length()); } return 0; }