1 solutions
-
0
C :
#include<stdio.h> int main() { char s[99]; int a, b, c, n = 0; while(scanf("%s", &s) == 1) { if(sscanf(s, "%d+%d=%d", &a, &b, &c) == 3 && a+b==c) n++; if(sscanf(s, "%d-%d=%d", &a, &b, &c) == 3 && a-b==c) n++; } printf("%d\n", n); return 0; }C++ :
#include<bits/stdc++.h> using namespace std; string a; int ans; int main() { while(cin>>a) { int x=0,s=0,b=0,bj=0; for(int i=0;i<a.size();i++) { if(a[i]>='0' && a[i]<='9') x=x*10+a[i]-'0'; else if(a[i]=='+') s+=x,x=0; else if(a[i]=='-') s+=x,x=0,bj=1; else if(a[i]=='=') { if(bj==0) s+=x; else s-=x; x=0; b=i; break; } } for(int i=b+1;i<a.size();i++) if(a[i]>='0' && a[i]<='9') x=x*10+a[i]-'0'; if(s==x) ans++; } cout<<ans<<endl; return 0; }
- 1
Information
- ID
- 16505
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By