Created
July 12, 2016 09:43
-
-
Save TheoKlein/104997f20785b5ead81940bb40048236 to your computer and use it in GitHub Desktop.
ZeroJudge b532
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <cctype> | |
| using namespace std; | |
| int main() { | |
| int num; | |
| cin >> num; | |
| while(num-- != 0){ | |
| int left = 0 , right = 0 , result = 0; | |
| char operation; | |
| bool center = false; | |
| string input; | |
| cin >> input; | |
| for(int i = 0 ; i < input.length() ; ++i){ | |
| if(input[i] == '+' || input[i] == '-' || input[i] == '*' || input[i] == '/' || input[i] == '%'){ | |
| operation = input[i]; | |
| center = true; | |
| }else if(isdigit(input[i])){ | |
| if(center){ | |
| if(right != 0) | |
| right *= 10; | |
| right += input[i] - '0'; | |
| }else{ | |
| if(left != 0) | |
| left *= 10; | |
| left += input[i] - '0'; | |
| } | |
| } | |
| } | |
| switch(operation){ | |
| case '+': | |
| result = left + right; | |
| break; | |
| case '-': | |
| result = left - right; | |
| break; | |
| case '*': | |
| result = left * right; | |
| break; | |
| case '/': | |
| result = left / right; | |
| break; | |
| case '%': | |
| result = left % right; | |
| break; | |
| } | |
| cout << result << endl; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment