fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <algorithm>
  5. #include <regex>
  6.  
  7. using namespace std;
  8.  
  9. bool myless(char l, char r) {
  10. return (int)l < (int)r;
  11. }
  12.  
  13.  
  14. int main()
  15. {
  16. string num1, num2;
  17. cin >> num1 >> num2;
  18.  
  19. auto pred = [](char ch){ return myless('0', ch) && !myless('9', ch); };
  20.  
  21. auto it1 = stable_partition(num1.begin(), num1.end(), pred);
  22. num1.erase(it1, num1.end());
  23. auto it2 = stable_partition(num2.begin(), num2.end(), pred);
  24. num2.erase(it2, num2.end());
  25.  
  26. cout << num1 << endl;
  27. cout << num2 << endl;
  28.  
  29.  
  30. // if (!regex_match(num1, regex("[0-9]+")))
  31. // cout << "invalid num" << endl;
  32. // if (!regex_match(num2, regex("[0-9]+")))
  33. // cout << "invalid num" << endl;
  34.  
  35. if (num1.size() < num2.size())
  36. cout << num1 + " is less than " + num2 << endl;
  37. else if(num1.size() > num2.size())
  38. cout << num1 + " is greater than " + num2 << endl;
  39. else
  40. {
  41. // auto mypair = mismatch(num1.cbegin(), num1.cend(), num2.cbegin());
  42. // if (mypair.first==num1.cend())
  43. // cout << num1 + " is equal to " + num2 << endl;
  44. // else if (myless(*mypair.first,*mypair.second))
  45. // cout << num1 + " is less than " + num2 << endl;
  46. // else /*if (myless(*mypair.second, *mypair.first))*/
  47. // cout << num1 + " is greater than " + num2 << endl;
  48. if(num1<num2)
  49. cout << num1 + " is less than " + num2 << endl;
  50. else if(num1>num2)
  51. cout << num1 + " is greater than " + num2 << endl;
  52. else
  53. cout << num1 + " is equal to " + num2 << endl;
  54. }
  55. }
Success #stdin #stdout 0s 3436KB
stdin
123457
123456
stdout
123457
123456
123457 is greater than 123456