1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| #include <iostream> #define ll long long using namespace std;
string str; int ptr = 0, len = 0; ll n = 0, a = 0, b = 0;
bool isNum(char ch) { if (ch >= '0' && ch <= '9') { return true; } else { return false; } }
long long getNum() { long long num = 0; while (isNum(str[ptr])) { num *= 10; num += str[ptr++] - '0'; if (ptr > len) break; } return num; }
int main(){ char c; scanf("%lld", &n); while(n--){ cin >> str; len = str.length(); ptr = 0; a = getNum(); c = str[ptr++];; b = getNum();
switch(c){ case '+':{ printf("%lld\n", a+b); break; } case '-':{ printf("%lld\n", a-b); break; } case '*':{ printf("%lld\n", a*b); break; } case '/':{ if(b == 0){ printf("No answer!\n"); break; } if(a % b){ printf("%.2f\n", double(a*1.00/b)); } else{ printf("%lld\n", a/b); } break; } } } return 0; }
|