fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. bool cmp(const string& a, const string& b) {
  7. int len = max(a.size(), b.size());
  8. for(int i = 0; i < len; i++) {
  9. char ac = i < a.size() ? a[i] : a[0];
  10. char bc = i < b.size() ? b[i] : b[0];
  11. if(ac > bc) return true;
  12. else if(ac < bc) return false;
  13. }
  14. return false;
  15. }
  16.  
  17. int main() {
  18. string number;
  19. vector<string> numbers;
  20. while(cin >> number) {
  21. numbers.push_back(number);
  22. }
  23. sort(numbers.begin(), numbers.end(), cmp);
  24. for(int i = 0; i < numbers.size(); i++) {
  25. cout << numbers[i] << endl;
  26. }
  27. return 0;
  28. }
Success #stdin #stdout 0s 3284KB
stdin
786
7863424
7867783
stdout
7867783
786
7863424