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;
    }
    
    


  • 相关阅读:
    springloud系列搭建注册中心
    在生产环境下禁用swagger
    consul怎么在windows下安装
    linux上传与下载
    使用git将本地代码提交到码云上去
    springboot整合activemq(三)配置文件
    springboot整合activemq(二),消费均匀分析
    Python3学习之路~3.2 递归、函数式编程、高阶函数、匿名函数、嵌套函数
    Python3学习之路~3.1 函数基本语法及特性、返回值、参数、局部与全局变量
    Python3学习之路~2.9 字符编码与转码
  • 原文地址:https://www.cnblogs.com/codeyuan/p/4254401.html
Copyright © 2011-2022 走看看