Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <sstream>
- #include <algorithm>
- using namespace std;
- bool sortInRev(const pair<int, string>& a, const pair<int, string>& b)
- {
- return (a.first > b.first);
- }
- int main()
- {
- int numberOfEquations;
- cin >> numberOfEquations;
- cin.ignore();
- vector<pair<double, string>> memory;
- for (int i = 0; i < numberOfEquations; i++)
- {
- string equation;
- getline(cin, equation);
- double first = 0.0;
- string operation;
- double second = 0.0;
- istringstream istr(equation);
- istr >> first >> operation >> second;
- double result = 0.0;
- if (operation == "+")
- {
- result = first + second;
- }
- else if (operation == "-")
- {
- result = first - second;
- }
- else if (operation == "*")
- {
- result = first * second;
- }
- else if (operation == "/")
- {
- result = first / second;
- }
- else
- {
- result = int(first) % int(second);
- }
- memory.push_back(pair<double, string>(result, equation));
- }
- sort(memory.begin(), memory.end(), sortInRev);
- for (int i = 0; i < memory.size(); i++)
- {
- cout << memory[i].second << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement