Advertisement
Guest User

Untitled

a guest
Apr 18th, 2021
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<sstream>
  4. #include<map>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. map<double, string, greater<double>>results; /// Container to store and sort the results
  11.  
  12. int numberOfEquations;
  13. cin >> numberOfEquations;
  14. cin.ignore();
  15.  
  16. for (int i = 0; i < numberOfEquations; i++)
  17. {
  18. string input;
  19. getline(cin, input);
  20. istringstream readLine(input);
  21.  
  22. string number1;
  23. string operation;
  24. string number2;
  25.  
  26. readLine >> number1; /// get the first number
  27. readLine >> operation; /// get the operation
  28. readLine >> number2; /// get the second number
  29.  
  30. double number;
  31.  
  32. if (operation == "+")
  33. {
  34. number = stoi(number1) + stoi(number2);
  35. }
  36. else if (operation == "-")
  37. {
  38. number = stoi(number1) - stoi(number2);
  39. }
  40. else if (operation == "*")
  41. {
  42. number = stoi(number1) * stoi(number2);
  43. }
  44. else if (operation == "/")
  45. {
  46. number = stoi(number1) * (1.0) / stoi(number2);
  47. }
  48. else if (operation == "%")
  49. {
  50. number = stoi(number1) % stoi(number2);
  51. }
  52.  
  53. results.insert(pair<double, string>(number, input));
  54.  
  55. }
  56. for (map<double, string>::iterator i = results.begin(); i != results.end(); i++)
  57. {
  58. cout << i->second << endl;
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement