fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define faster ios_base::sync_with_stdio(false) ; cin.tie(NULL)
  4.  
  5. string s;
  6.  
  7. void inp(){
  8. cin >> s;
  9. }
  10.  
  11. string Max(string &s1 , string &s2){
  12. if (s1.size() < s2.size()) return s2;
  13. if (s1.size() > s2.size()) return s1;
  14. if (s1 >= s2) return s1;
  15. return s2;
  16. }
  17.  
  18. void solve(){
  19. string res = "";
  20. int i = 0;
  21. while (i < s.size()){
  22. if (!isdigit(s[i]) || s[i] == '0'){
  23. ++i;
  24. continue;
  25. }
  26. string x;
  27. x += s[i];
  28. while (i < s.size() - 1 && isdigit(s[i + 1])){
  29. ++i;
  30. x += s[i];
  31. }
  32. res = Max(res , x);
  33. ++i;
  34. }
  35. if (res.size() == 0) cout << -1;
  36. else cout << res;
  37. }
  38.  
  39. int main(){
  40. faster;
  41. inp();
  42. solve();
  43. return 0;
  44. }
  45.  
Success #stdin #stdout 0.01s 5304KB
stdin
Standard input is empty
stdout
-1