Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<sstream>
- #include<map>
- using namespace std;
- int main()
- {
- map<double, string, greater<double>>results; /// Container to store and sort the results
- int numberOfEquations;
- cin >> numberOfEquations;
- cin.ignore();
- for (int i = 0; i < numberOfEquations; i++)
- {
- string input;
- getline(cin, input);
- istringstream readLine(input);
- string number1;
- string operation;
- string number2;
- readLine >> number1; /// get the first number
- readLine >> operation; /// get the operation
- readLine >> number2; /// get the second number
- double number;
- if (operation == "+")
- {
- number = stoi(number1) + stoi(number2);
- }
- else if (operation == "-")
- {
- number = stoi(number1) - stoi(number2);
- }
- else if (operation == "*")
- {
- number = stoi(number1) * stoi(number2);
- }
- else if (operation == "/")
- {
- number = stoi(number1) * (1.0) / stoi(number2);
- }
- else if (operation == "%")
- {
- number = stoi(number1) % stoi(number2);
- }
- results.insert(pair<double, string>(number, input));
- }
- for (map<double, string>::iterator i = results.begin(); i != results.end(); i++)
- {
- cout << i->second << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement