参考代码:
#include<bits/stdc++.h>//100以内数的加减 using namespace std; bool jiancha(string s) { string a,b,c; int flag=0; if(s[(int)s.size()-1]=='?') return false; else { for(int i=0;i<(int)s.size();i++) { if(s[i]>='0'&&s[i]<='9'&&flag==0) { a+=s[i]; } if(s[i]>='0'&&s[i]<='9'&&flag==1) { b+=s[i]; } if(s[i]>='0'&&s[i]<='9'&&flag==2) { c+=s[i]; } else if(s[i]=='+'||s[i]=='-'||s[i]=='=') { flag++; } } int a1=stoi(a); int b1=stoi(b); int c1=stoi(c); if((int)s.find('+')!=-1) { if(a1+b1==c1) return true; else return false; } else if((int)s.find('-')!=-1) { if(a1-b1==c1) return true; else return false; } } } int main() { int cnt=0; string s; while(cin>>s) { if(jiancha(s)==true) cnt++; } cout<<cnt<<endl; return 0; }
0.0分
1 人评分