1012: 弟弟的作业

来源:互联网 发布:大数据预测性分析方法 编辑:程序博客网 时间:2024/06/11 13:51

1012: 弟弟的作业

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 19  Solved: 11
[Submit][Status][Discuss]

Description

你的弟弟刚做完了“100以内数的加减法”这部分的作业,请你帮他检查一下。每道题目(包括弟弟的答案)的格式为a+b=c或者a-b=c,其中ab是作业中给出的,均为不超过100的非负整数;c是弟弟算出的答案,可能是不超过200的非负整数,也可能是单个字符"?",表示他不会算。

Input

输入文件包含不超过100行,以文件结束符结尾。每行包含一道题目,格式保证符合上述规定,且不包含任何空白字符。输入的所有整数均不含前导0。

Output

输出仅一行,包含一个非负整数,即弟弟答对的题目数量。

Sample Input

1+2=33-1=56+7=?99-0=99

Sample Output

2



#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;}//sscanf() - 从一个字符串中读进与指定格式相符的数据,头文件为stdio.h,这是个知识点,挺不错


#include<iostream>#include<stdio.h>using namespace std;int  main(){    int a,c,e,n=0;    char b,d,s[20];    while((scanf("%d%c%d%c%s",&a,&b,&c,&d,&s)!=EOF))    {       int i=0;       if(s[i]>='0'&&s[i]<='9')       {           e=0;           while(s[i]>='0'&&s[i]<='9')          {              e=e*10+(s[i]-'0');//类型转换              i++;          }             cout<<e<<endl;       }       if(b=='+'&&a+c==e)          n++;       if(b=='-'&&a-c==e)          n++;   }       cout<<n<<endl;   return 0;}



2 0
原创粉丝点击