zoukankan      html  css  js  c++  java
  • 第一轮 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("
    lllllll:%c
    ",s.top());
        while(!s.empty()){
            int k=s.top()-'0';
            a=a+k*t;
            s.pop();
         //   printf("
    K:%d,A:%d
    ",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
    ");
            get();
           // printf("
    A:%d,B:%d,C:%d
    ",a,b,c);
            if(cc=='+'){if(a+b==c) ans++;}
            if(cc=='-'){if(a-b==c) ans++;}
           // printf("%d
    ",ans);
            memset(str,0,sizeof(str));
        }
        printf("%d
    ",ans);
        return 0;
    }
    
    


  • 相关阅读:
    ASP.NET AJAX 1.0 英文文档,视频教程
    第十五篇: Ajax Control Toolkit 控件包3. DragPanel (拖动效果)
    第二篇: Silverlight 下载与安装
    第十二篇: Ajax Control Toolkit 控件包1. Accordion (多层折叠效果)
    第一篇: Silverlight 效果展示
    第十四篇: 建立 AJAX 母版页 (为了后面例子方便)
    第三篇: Silverlight 2.0 下载与安装
    第十三篇: Ajax Control Toolkit 控件包2. CollapsiblePanel (展开和折叠效果)
    第十六篇: Ajax Control Toolkit 控件包4. DropShadow (阴影效果)
    ENDNOTE使用方法(转发)
  • 原文地址:https://www.cnblogs.com/codeyuan/p/4254401.html
Copyright © 2011-2022 走看看