第一轮 E

 Homework Checker
Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu
Submit Status

Description
Download as PDF

  Homework Checker 
  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 
/*************************************************************************
	> File Name: d.cpp
	> Author: 
	> Mail: 
	> Created Time: 2014年11月09日 星期日 11时07分49秒
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<stack>
using namespace std;
int a,b,c;
int ans;
char str[20],cc;
stack<char> s;
void get()
{ 
    while(!s.empty()) s.pop();
  int i;
  for(i=0;i<strlen(str);i++)
    {
        if(str[i]=='+'||str[i]=='-') break;
        s.push(str[i]);
    }
    cc=str[i];
    int t=1;a=0;
   // printf("\nlllllll:%c\n",s.top());
    while(!s.empty()){
        int k=s.top()-'0';
        a=a+k*t;
        s.pop();
     //   printf("\nK:%d,A:%d\n",k,a);
        t=t*10;
    }
    t=1;b=0;
    while(!s.empty()) s.pop();
    for(i=i+1;i<strlen(str);i++)
    {
        if(str[i]=='=') break;
        s.push(str[i]);
    }
    while(!s.empty()){
        int k=s.top()-'0';
        b=b+k*t;
        s.pop();
        t=t*10;
    }
    i=i+1;
    if(str[i]=='?') c=300;
    else{
        while(!s.empty()) s.pop();
        for(;i<strlen(str);i++)
        {
         s.push(str[i]);
        }
        t=1;c=0;
        while(!s.empty()){
            int k=s.top()-'0';
            c=c+k*t;
            s.pop();
            t=t*10;
        }
    }
}
int main()
{
    ans=0;
    memset(str,0,sizeof(str));
    while(~scanf(" %s",str)){
       // printf("%s",str);
       // printf("zhang\n");
        get();
       // printf("\nA:%d,B:%d,C:%d\n",a,b,c);
        if(cc=='+'){if(a+b==c) ans++;}
        if(cc=='-'){if(a-b==c) ans++;}
       // printf("%d\n",ans);
        memset(str,0,sizeof(str));
    }
    printf("%d\n",ans);
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值