nyoj-486-Old Calculator
来源:互联网 发布:淘宝店铺首页怎么做 编辑:程序博客网 时间:2024/05/09 11:32
Old Calculator
时间限制:1000 ms | 内存限制:65535 KB
难度:1
- 描述
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.
- 样例输入
51+2=322-3=-14*5=206/0=1228%9=0
- 样例输出
Wrong Answer3AcceptAcceptInput ErrorWrong Answer8
- 来源
- szhhck的水库
- 上传者
ACM_宋志恒
#include "iostream"using namespace std;int main(int argc, char const *argv[]){int n;cin>>n;while(n--){int a,b,c;char x,y;cin>>a>>x>>b>>y>>c;if(x=='+'&&a+b==c)cout<<"Accept"<<endl;//四种情况else if(x=='+'&&a+b!=c)cout<<"Wrong Answer\n"<<a+b<<endl;if(x=='-'&&a-b==c)cout<<"Accept"<<endl;else if(x=='-'&&a-b!=c)cout<<"Wrong Answer\n"<<a-b<<endl;if(x=='*'&&a*b==c)cout<<"Accept"<<endl;else if(x=='*'&&a*b!=c)cout<<"Wrong Answer\n"<<a*b<<endl; if(x=='/'&&b==0) cout<<"Input Error"<<endl; else if(x=='/'&&a/b==c)cout<<"Accept"<<endl;else if(x=='/'&&a/b!=c)cout<<"Wrong Answer\n"<<a/b<<endl;if(x=='%'&&a%b==c)cout<<"Accept"<<endl;else if(x=='%'&&a%b!=c) cout<<"Wrong Answer\n"<<a%b<<endl;}return 0;}
#include<stdio.h>int calc(int a,char o,int b){switch(o){case '+':return a+b;case '-':return a-b;case '*':return a*b;case '/':return a/b;case '%':return a%b;}}int main(){int ncase;int a,b,c,r;char o;scanf("%d",&ncase);while(ncase--){scanf("%d%c%d=%d",&a,&o,&b,&c);if((o=='/'||o=='%')&&b==0){puts("Input Error");continue;}r=calc(a,o,b);if(r==c)puts("Accept");elseprintf("Wrong Answer\n%d\n",r);}return 0;}
0 0
- NYOJ 486 Old Calculator
- nyoj-486-Old Calculator
- NYOJ 486题 Old Calculator
- Old Calculator
- Old Calculator
- Calculator
- Calculator
- Calculator
- Calculator
- Calculator
- Calculator
- calculator
- Calculator
- Calculator
- calculator
- Calculator
- Calculator
- Calculator| ||
- [转载] [强烈推荐]大牛对计算机读研的看法
- sql server 远程过程调用失败 0x800706be 解决方法
- 东风风行网络
- 在Windows下快速搭建Jetty版本——Nexus私服
- Index statistics collected bug
- nyoj-486-Old Calculator
- 使用windows服务管理对WAS进行停止和重启操作时后台出现凭证失败的错误解决办法
- Python——Matrix Decomposition
- UVA 10003 - Cutting Sticks
- DOM的滚动
- 初到Sharepoint
- 最近学习、工作计划
- 机器学习之&&Andrew Ng课程复习--- 学习笔记(一、二课)
- Linux下nm和ldd 命令