1018: Brother's homework time limit:1 Sec Memory limit:128 MB
submit:413 solved:188
[Submit] [Status] [BBS] Description
Your brother just finished the "Plus and minus " part of the homework, please help him check it. The format of each topic (including the brother's answer) is a+b=c or a-b=c, where A and B are given in the assignment and are non-negative integers that do not exceed the number of;c is the brother to figure out the answer, may be not more than a non-negative integer, may be a single character "?" , which means he can't count.
Input
The input file contains no more than a few lines, ending with a file terminator. Each row contains a title that is guaranteed to conform to the above and does not contain any whitespace characters. All integers entered do not contain a leading 0.
Output
Output only one line, including a non-negative integer, that is, the number of questions the brother answered correctly.
Sample Input1+2=33-1=56+7=?99-0=99Sample Output2HINT
! =eof Here you need to press two times Ctrl Z and then enter because here S is Char
int sscanf (const char *buffer,const char *format,[argument] ...); The data stored in buffer is formatted with the format Control string argument the selective setting string sscanf reads data from buffer and writes the data to the argument according to format.
#include <stdio.h>intMain () {inta,b,f,d,j,c,t= -, sum=0; Chars[101]; while(SCANF ("%s", &s)! =EOF) { if(SSCANF (s),"%d+%d=%d", &a,&b,&c) = =3&&A+B==C)//Success returns the number of arguments{sum++; } if(SSCANF (s),"%d-%d=%d", &a,&b,&c) = =3&&a-b==c) {sum++; }} printf ("%d\n", sum); return 0;}
Brother's Homework