fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4.  
  5. bool cmp (string a, string b) {
  6. // a > b
  7.  
  8. auto x = a.find_first_not_of('0');
  9. auto y = b.find_first_not_of('0');
  10. a.erase (0, x);
  11. b.erase (0, y);
  12.  
  13. if (a.size() != b.size()) {
  14. return a.size() < b.size();
  15. }
  16. else {
  17. for (ll i = 0; i < a.size(); i++) {
  18. if (a[i] != b[i]) {
  19. return a[i] < b[i];
  20. }
  21. }
  22. }
  23. return 0;
  24. }
  25.  
  26. int main () {
  27. ios_base::sync_with_stdio(0);
  28. cin.tie(0); cout.tie(0);
  29.  
  30. if (fopen ("greencode.inp", "r")) {
  31. freopen ("greencode.inp", "r", stdin);
  32. freopen ("greencode.out", "w", stdout);
  33. }
  34.  
  35. string s;
  36. getline (cin, s);
  37. s += " ";
  38. string t = "";
  39. vector <string> a;
  40. bool ok = 0;
  41.  
  42. for (ll i = 0; i < s.size(); i++) {
  43. if (ok == 0) {
  44. if (s[i] >= '0' && s[i] <= '9') {
  45. t += s[i];
  46. ok = 1;
  47. }
  48. }
  49. else {
  50. if (s[i] >= '0' && s[i] <= '9') {
  51. t += s[i];
  52. }
  53. else {
  54. a.push_back(t);
  55. t = "";
  56. ok = 0;
  57. }
  58. }
  59. }
  60.  
  61. sort (a.begin(), a.end(), cmp);
  62. for (ll i = 0; i < a.size(); i++) {
  63. cout << a[i] << " ";
  64. }
  65.  
  66.  
  67. return 0;
  68. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty