题目描述
你的弟弟刚做完了“100以内数的加减法”这部分的作业,请你帮他检查一下。每道题目(包括弟弟的答案)的格式为a+b=c或者a-b=c,其中a和b是作业中给出的,均为不超过100的非负整数;c是弟弟算出的答案,可能是不超过200的非负整数,也可能是单个字符"?",表示他不会算。
输入
输入文件包含不超过100行,以文件结束符结尾。每行包含一道题目,格式保证符合上述规定,且不包含任何空白字符。输入的所有整数均不含前导0。
输出
输出仅一行,包含一个非负整数,即弟弟答对的题目数量。
样例输入
1+2=3
3-1=5
6+7=?
99-0=99
样例输出
2
#include<stdio.h>
#include<string.h>
int fun(char *p);
int main()
{
int t=0,x,y;
char c1,c2,z[10];
while(scanf("%d%c%d%c%s",&x,&c1,&y,&c2,z)!=EOF)
{
if(z[0]!='?')
{
if(c1=='-')
if(x-y==fun(z))
{t++;}
if(c1=='+')
if(x+y==fun(z))
{t++;}
}
}
printf("%d\n",t);
}
int fun(char *p)
{
int s=0;
while(*p!=0)
{
s=s*10+(*p-'0');
*p++;
}
return s;
}
#include<stdio.h>
int main(){
int x,y,z,s=0;
char f,i;
while(scanf("%d%c%d=%d",&x,&f,&y,&z)!=EOF){
getchar();
i=z;
if(i=='?'){
continue;
}
else if(f=='+'&&x+y==z){
s++;
}
else if(f=='-'&&x-y==z){
s++;
}
printf("%d\n",s);
}
}