zoukankan      html  css  js  c++  java
  • Old Calculator

    描述

    szhhck have an old calculator bought 5 years ago.he find the old machine can just calculate expressions like this  :

    A-B、A+B、A*B、A/B、A%B.

    because it is too old and long time not use,the old machine maybe conclude a wrong answer sometime.

    Your task is to write a program to check the answer the old calculator calculates is correct or not.

    输入
    First input is a single line,it's N and stands for there are N test cases.then there are N lines for N cases,each line contain an equation like A op B = C(A,B and C are all integers,and op can only be + , - , * , / or % ).
    More details in the Sample Input.
    输出
    For each test case,if the equation is illegal(divided or mod by zero),you should Output "Input Error".and if the equation is correct,Output "Accept";if not Output "Wrong Answer",and print the right answer after a blank line.
    样例输入
    5
    1+2=32
    2-3=-1
    4*5=20
    6/0=122
    8%9=0
    样例输出
    Wrong Answer
    3
    Accept
    Accept
    Input Error
    Wrong Answer
    8

     1 #include <stdio.h>
     2 
     3 int main(){
     4     int T;
     5     int a;
     6     int b;
     7     int c;
     8     char sign;
     9     
    10     scanf("%d",&T);
    11     
    12     while(T--){
    13         scanf("%d%c%d=%d",&a,&sign,&b,&c);
    14         
    15         if(sign=='+'){
    16             if(a+b==c)
    17                 printf("Accept
    ");
    18                 
    19             else
    20                 printf("Wrong Answer
    %d
    ",a+b);
    21         }
    22         
    23         else if(sign=='-'){
    24             if(a-b==c)
    25                 printf("Accept
    ");
    26                 
    27             else
    28                 printf("Wrong Answer
    %d
    ",a-b);
    29         }
    30         
    31         else if(sign=='*'){
    32             if(a*b==c)
    33                 printf("Accept
    ");
    34                 
    35             else
    36                 printf("Wrong Answer
    %d
    ",a*b);
    37         }
    38         
    39         else if(sign=='/'){
    40             if(b==0)
    41                 printf("Input Error
    ");
    42             
    43             else if(a/b==c)
    44                 printf("Accept
    ");
    45                 
    46             else
    47                 printf("Wrong Answer
    %d
    ",a/b); 
    48         }
    49         
    50         else if(sign=='%'){
    51             if(b==0)
    52                 printf("Input Error
    ");
    53             
    54             else if(a%b==c)
    55                 printf("Accept
    ");
    56                 
    57             else
    58                 printf("Wrong Answer
    %d
    ",a%b); 
    59         }
    60     } 
    61     
    62     return 0;
    63 }
     
  • 相关阅读:
    一套完整的测试应该由哪些阶段组成?
    测试结束的标准是什么?
    :你的测试职业发展目标是什么?
    您认为做好测试用例设计工作的关键是什么?
    Servlet API中forward()与redirect()的区别?
    AOP 核心概念?
    Spring 中使用了哪些设计模式?
    ArrayList类?
    如何实现拦截器?
    什么是集合?
  • 原文地址:https://www.cnblogs.com/zqxLonely/p/4100160.html
Copyright © 2011-2022 走看看