fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5.  
  6. vector<string>num; //mang xau
  7. vector<string>num2;
  8.  
  9. bool isNumber (string s)
  10. {
  11. for (int i = 0; i < s.size(); i++)
  12. {
  13. if (isdigit(s[i]) == false) return false;
  14. }
  15. return true;
  16. }
  17.  
  18. bool isDigit(char s)
  19. {
  20. if (s >= '0' && s <= '9') return true;
  21. else return false;
  22. }
  23.  
  24. string Erase_Useless_Zero(string s)
  25. {
  26. while (s[0] == '0') s.erase(0,1);
  27. return s;
  28. }
  29.  
  30. string maximize(string a, string b)
  31. {
  32. if (a[0] == '-' && b[0] != '-') return b;
  33. if (a[0] != '-' && b[0] == '-') return a;
  34. if (a[0] == '-' && b[0] == '-') return min(a,b);
  35. if (a[0] == '-' && b[0] == '0') return b; //neu co 0
  36. if (a[0] == '0' && b[0] == '-') return a; //neu co 0
  37. if (a.size() < b.size()) return b;
  38. if (a.size() > b.size()) return a;
  39. return max(a,b);
  40. }
  41.  
  42. signed main()
  43. {
  44. ios_base::sync_with_stdio(0);
  45. cin.tie(0);
  46. cout.tie(0);
  47. string s;
  48. getline(cin, s);
  49. if (isNumber(s) == true)
  50. {
  51. s = Erase_Useless_Zero(s);
  52. cout << s;
  53. return 0;
  54. }
  55. string ans = "0";
  56. string res = "";
  57. for (int i = 0; i < s.size(); i++)
  58. {
  59. if (isDigit(s[i]) == true || s[i] == '-')
  60. {
  61. if (res == "" && s[i] == '0') continue;
  62. else res.push_back(s[i]);
  63. }
  64. else
  65. {
  66. if (res != "")
  67. {
  68. ans = maximize(res, ans);
  69. res = "";
  70. }
  71. }
  72. }
  73. ans = maximize(ans,res);
  74. cout << ans;
  75. return 0;
  76. }
  77.  
Success #stdin #stdout 0s 5412KB
stdin
Abc987hnmh0003456hs006543m
stdout
6543