• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • YouClaw
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Uva 11878 - Homework Checker

你为何这么叼!

Homework Checker

 Time limit: 1.000 seconds

 

� Your younger brother has just finished his homework for the part "additions and subtractions for integers not greater than one hundred" and asks you to check the answers. Each question (together with the answer computed by your younger brother) is formatted either as a + b = c or a - b = c, where a and b are numbers prepared by the teacher (they are guaranteed to be non-negative integers not greater than 100), c is the answer computed by your younger brother and is either a non-negative integer not greater than 200, or a single character `?' (that means, he is unable to compute the answer).

Input 

There will be at most 100 lines in the input. Each line contains a question with your younger brother's answer, formatted as stated above. There will be no space characters in each line (excluding the newline character). Numbers will never have leading zeros.

Output 

Print a single integer in a line, the number of correct answers.

Sample Input 

1+2=3
3-1=5
6+7=?
99-0=99

Sample Output 

2

 


Problemsetter: Rujia Liu, Special Thanks: Yiming Li

 

 1 #include <cstdio>
 2 #include <vector>
 3 #include <cstring>
 4 #include <algorithm>
 5 using namespace std;
 6 #define maxn 555
 7 int n,m;
 8 int main(){
 9     char s[50];
10     int x[50];
11     int a,b,c,x1,x2,flag,k=0;
12     while(~scanf("%s",s)){
13         n=strlen(s);
14         memset(x,0,sizeof x);
15         if(s[n-1]=='?')continue;
16         for(int i=0;i<n;i++)x[i]=s[i]-'0';
17         for(int i=0;i<n;i++){
18             if(s[i]=='+'){flag=0;x1=i;}
19             if(s[i]=='-'){flag=1;x1=i;}
20             if(s[i]=='=')x2=i;
21         }
22         a=0;b=0;c=0;
23         for(int i=0;i<x1;i++)a=a*10+x[i];
24         for(int i=x1+1;i<x2;i++)b=b*10+x[i];
25         for(int i=x2+1;i<n;i++)c=c*10+x[i];
26         if(flag==0)if(a+b==c)k++;
27         if(flag==1)if(a-b==c)k++;
28     }
29     printf("%d\n",k);
30     return 0;
31 }
View Code 2013-10-09 10:27:44 

 

posted @ 2013-10-09 10:27  HaibaraAi  阅读(206)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3