Younger brother's homework (hpu1164) and younger brother's homework hpu1164
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 74 Solved: 37
[Submit] [Status] [Web Board] Description
Your younger brother has just completed the assignment of "adding and subtracting less than 100". Please check it for him. The format of each question (including the answer of the younger brother) isA+B=COrA-B=C, WhereAAndBIs a non-negative integer not greater than 100 given in the job;CThe answer is calculated by the younger brother. It may be a non-negative integer not greater than 200, or a single character "? ", Indicating that he will not calculate.
Input
The input file contains no more than 100 lines and ends with a file Terminator. Each line contains a question. The format must comply with the preceding rules and does not contain any blank characters. All input integers do not contain leading 0.
Output
The output contains only one row, which contains a non-negative integer, that is, the number of correct answers.
Sample Input1 + 2 = 33-1 = 56 + 7 =? 99-0 = 99 Sample Output2HINT
Source
Hunan sixth College Computer Program Design Competition
#include<stdio.h>#include<string.h>int main(){int a,b,d,sum=0,len; char s,c[4]; while(scanf("%d%c%d=%s",&a,&s,&b,c)!=EOF){ len=strlen(c);if(c[0]!='?') { if(len==1)d=c[0]-'0'; if(len==2) d=(c[0]-'0')*10+c[1]-'0'; if(len==3) d=(c[0]-'0')*100+(c[1]-'0')*10+c[2]-'0'; if(s=='+') { if(a+b==d) sum++; } if(s=='-') { if(a-b==d) sum++; } } } printf("%d\n",sum); return 0; }