NYOJ 486 Old Calculator

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.
样例输入
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

思路:略

 

#include<stdio.h>
int main()
{
	int m;
	scanf("%d",&m);
	while(m--)
	{
		int a,b,sum;
		char ch;
		scanf("%d%c%d=%d",&a,&ch,&b,&sum);
		switch(ch)
		{
		case '+':
			if (a+b == sum)
			{
				printf("Accept\n");
			}
			else
			{
				printf("Wrong Answer\n%d\n",a+b);
			}
			break;
		case '-':
			if (a-b == sum)
			{
				printf("Accept\n");
			}
			else
			{
				printf("Wrong Answer\n%d\n",a-b);
			}
			break;
		case '*':
			if (a*b == sum)
			{
				printf("Accept\n");
			}
			else
			{
				printf("Wrong Answer\n%d\n",a*b);
			}
			break;
		case '/':
			if (b == 0)
			{
				printf("Input Error\n");
			}
			else
			{
				if (a/b == sum)
				{
					printf("Accept\n");
				}
				else
				{
					printf("Wrong Answer\n%d\n",a/b);
				}
			}
			break;
		case '%':
			if (b == 0)
			{
				printf("Input Error\n");
			}
			else
			{
				if (a%b == sum)
				{
					printf("Accept\n");
				}
				else
				{
					printf("Wrong Answer\n%d\n",a%b);
				}
			}
			break;
		}
	}
}


 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值