Balloon Comes!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 19686 Accepted Submission(s): 7408
Give you an operator (+,-,*, / --denoting addition, subtraction, multiplication, division respectively) and two positive integers, your task is to output the result.
Is it very easy?
Come on, guy! PLMM will send you a beautiful Balloon right now!
Good Luck!
4 + 1 2 - 1 2 * 1 2 / 1 2
3 -1 2 0.50
#include<stdio.h>
#include<string.h>
int main()
{
int t,x,y;
char a;
scanf("%d",&t);
while(t--)
{
getchar();
scanf("%c %d %d",&a,&x,&y);
if(a=='+')
{
printf("%d\n",x+y);
}
if(a=='-')
{
printf("%d\n",x-y);
}
if(a=='*')
{
printf("%d\n",x*y);
}
if(a=='/')
{
if(x%y==0)
printf("%d\n",x/y);
else
printf("%.2f\n",(double)x/y);
}
}
return 0;
}
//怎样输出运算符 ,当做字符
不能用while(scanf()!=EOF).会超时 只能用scanf;
整除时不能输出浮点数,
如果比赛遇到这题,,,,