-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathARITH2.cpp
More file actions
54 lines (50 loc) · 714 Bytes
/
ARITH2.cpp
File metadata and controls
54 lines (50 loc) · 714 Bytes
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
/*
USER: zobayer
TASK: ARITH2
ALGO: ad-hoc
*/
#include <stdio.h>
#define i64 long long
bool isnum(char *str, i64 &n, char &op)
{
n = 0;
if(str[0]<'0' || str[0]>'9')
{
op = str[0];
return false;
}
for(int i=0; str[i]; i++)
n = n*10 + (str[i]-'0');
return true;
}
int main()
{
char token[30], op;
int n;
i64 ans, num;
scanf("%d", &n);
while(n--)
{
ans = 0;
op = '+';
while(scanf("%s", token)==1)
{
if(isnum(token, num, op))
{
switch(op)
{
case '+': ans += num; break;
case '-': ans -= num; break;
case '*': ans *= num; break;
case '/': ans /= num; break;
}
}
else if(op == '=')
{
printf("%lld\n", ans);
break;
}
}
}
return 0;
}