#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
int a, b, ans, cnt = 0;
string equation, x, y, answer;
while(getline(cin, equation)){
int l = equation.size(), j = 0;
for(int i = j; i < l; i++){
if(equation[i] == '+' || equation[i] == '-'){j++;break;}
x.push_back(equation[i]);j++;
}
for(int i = j; i < l; i++){
if(equation[i] == '='){j++;break;}
y.push_back(equation[i]);j++;
}
for(int i = j; i < l; i++){
if(equation[i] == '\0'){j++;break;}
answer.push_back(equation[i]);j++;
}
int l1 = x.size(), l2 = y.size(), l3 = answer.size();
a = x[0] - 48;
for(int i = 1; i < l1; i++){
a = (a*10) + (x[i]-48);
}
b = y[0] - 48;
for(int i = 1; i < l2; i++){
b = (b*10) + (y[i]-48);
}
ans = answer[0] - 48;
for(int i = 1; i < l3; i++){
ans = (ans*10) + (answer[i]-48);
}
int sol;
for(int i = 0; i < l; i++)
if(equation[i] == '+'){
sol = a + b;
if(sol == ans)cnt++;
break;
}
else if(equation[i] == '-'){
sol = a - b;
if(sol == ans)cnt++;
break;
}
x.clear();y.clear();answer.clear();equation.clear();
}
cout << cnt << endl;
return 0;
}
#include <vector>
#include <cmath>
using namespace std;
int main(){
int a, b, ans, cnt = 0;
string equation, x, y, answer;
while(getline(cin, equation)){
int l = equation.size(), j = 0;
for(int i = j; i < l; i++){
if(equation[i] == '+' || equation[i] == '-'){j++;break;}
x.push_back(equation[i]);j++;
}
for(int i = j; i < l; i++){
if(equation[i] == '='){j++;break;}
y.push_back(equation[i]);j++;
}
for(int i = j; i < l; i++){
if(equation[i] == '\0'){j++;break;}
answer.push_back(equation[i]);j++;
}
int l1 = x.size(), l2 = y.size(), l3 = answer.size();
a = x[0] - 48;
for(int i = 1; i < l1; i++){
a = (a*10) + (x[i]-48);
}
b = y[0] - 48;
for(int i = 1; i < l2; i++){
b = (b*10) + (y[i]-48);
}
ans = answer[0] - 48;
for(int i = 1; i < l3; i++){
ans = (ans*10) + (answer[i]-48);
}
int sol;
for(int i = 0; i < l; i++)
if(equation[i] == '+'){
sol = a + b;
if(sol == ans)cnt++;
break;
}
else if(equation[i] == '-'){
sol = a - b;
if(sol == ans)cnt++;
break;
}
x.clear();y.clear();answer.clear();equation.clear();
}
cout << cnt << endl;
return 0;
}
No comments:
Post a Comment