-
Notifications
You must be signed in to change notification settings - Fork 0
/
Phd.cc
46 lines (37 loc) · 862 Bytes
/
Phd.cc
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
#include <iostream>
using namespace std;
int getNum(const string);
int main() {
int iters;
string formula;
cin >> iters;
for(int i = 0; i < iters; i++) {
cin >> formula;
if(formula == "P=NP")
{
cout << "skipped" << endl;
continue;
}
int ans = getNum(formula);
cout << ans << endl;
}
}
int getNum(const string formula) {
int n1 = 0, n2 = 0;
int length = formula.length();
bool passedOperator = false;
for(int i = 0; i < length; i++) {
if(formula[i] == '+') {
passedOperator = true;
continue;
}
if(passedOperator) {
n2*=10;
n2+= formula[i] - '0';
} else {
n1*=10;
n1+= formula[i] - '0';
}
}
return n1+n2;
}