-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathARITH2.cpp
More file actions
54 lines (49 loc) · 690 Bytes
/
Copy pathARITH2.cpp
File metadata and controls
54 lines (49 loc) · 690 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
#include <iostream>
#include <cctype>
#include <cstring>
using namespace std;
long long Value(char word[])
{
long long sum = 0;
for (int i = 0; i < strlen(word); ++i)
{
if(!isdigit(word[i]))
return -1;
else
sum = sum*10 + int(word[i] - '0');
}
return sum;
}
int main()
{
int t;
cin>>t;
while(t--)
{
char c[100];
cin>>c;
long long x = Value(c);
while(1)
{
char op;
cin>>c;
op = c[0];
if(op == '=')
break;
else
{
cin>>c;
long long y = Value(c);
if(op == '+')
x = x + y;
else if(op == '-')
x = x - y;
else if(op == '*')
x = x * y;
else if(op == '/')
x = x / y;
}
}
cout<<x<<endl;
}
}