http://acm.hdu.edu.cn/showproblem.php?pid=1170
这题麻烦在于每次输入之后的接收回车,还有对结果是否是整数的判断,The result should be rounded to 2 decimal places If and only if it is not an integer.
View Code
#include<stdio.h> #include<conio.h> int main() { int a,b,t,ans1; double ans2; char c,s[20]; scanf("%d",&t); gets(s); while(t--) { scanf("%c%d%d",&c,&a,&b); gets(s); if(c=='+') ans1=a+b; else if(c=='-') ans1=a-b; else if(c=='*') ans1=a*b; else if(c=='/') ans2=(double)a/(double)b; if(c=='/') { if(a%b==0) printf("%.0lf\n",ans2); else printf("%.2lf\n",ans2); } else printf("%d\n",ans1); } return 0; }