Younger brother job time limit: 1000 MS | memory limit: 65535 KB difficulty: 1
-
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.
-
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.
-
The output contains only one row, which contains a non-negative integer, that is, the number of correct answers.
-
Sample Input
1+2=3
3-1=5
6+7=?
99-0=99
-
Sample output
2
Simple question!
AC code:
#include
int main(){int count=0,i,a,b,c;char str[10],op;while(~scanf("%s",str)){i=0;a=0;while(str[i]>='0'&&str[i]<='9'){a=a*10+(str[i]-'0');i++;}op=str[i];i++;b=0;while(str[i]>='0'&&str[i]<='9'){b=b*10+(str[i]-'0');i++;}i++;if(str[i]>='0'&&str[i]<='9'){c=0;while(str[i]>='0'&&str[i]<='9'){c=c*10+(str[i]-'0');i++;}}elsec=-1;if(((op=='+')&&(a+b==c))||((op=='-')&&(a-b==c)))count++;}printf("%d\n",count);return 0;}