Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stack>
- #include <sstream>
- #include <map>
- using namespace std;
- void operationNstore ( multimap < int , string > &database , int N )
- {
- for ( int i = 0 ; i < N ; ++i )
- {
- string line ;
- int a = 0 ;
- int b = 0 ;
- int res = 0 ;
- char op = '_' ;
- getline ( cin , line ) ;
- istringstream istr ( line ) ;
- istr >> a >> op >> b ;
- switch ( op )
- {
- case '+':
- {
- res = a + b ;
- }
- break ;
- case '-':
- {
- res = a - b ;
- }
- break ;
- case '*':
- {
- res = a * b ;
- }
- break;
- case '/' :
- {
- res = a / b ;
- }
- break ;
- case '%' :
- {
- res = a%b ;
- }
- break;
- }
- database.insert ( { res , line } ) ;
- }
- }
- int main()
- {
- multimap < int , string > database ;
- stack < string > reversePrint ;
- int N = 0 ;
- string line ;
- getline ( cin , line ) ;
- N = stoi ( line ) ;
- operationNstore( database , N ) ;
- cout << endl ;
- for ( multimap < int , string > :: iterator it = database.begin() ; it != database.end() ; ++it )
- {
- reversePrint.push ( it -> second ) ;
- }
- while ( !reversePrint.empty() )
- {
- cout << reversePrint.top() << endl ;
- reversePrint.pop() ;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement