Skip to content

Instantly share code, notes, and snippets.

@TheoKlein
Created July 12, 2016 09:43
Show Gist options
  • Select an option

  • Save TheoKlein/104997f20785b5ead81940bb40048236 to your computer and use it in GitHub Desktop.

Select an option

Save TheoKlein/104997f20785b5ead81940bb40048236 to your computer and use it in GitHub Desktop.
ZeroJudge b532
#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