分析:题目不难,但又陷阱,导致我错了一次又一次,那就是OUTPUT 中的一句话,"The result should be rounded to 2 decimal places If and only if it is not an integer. ",如果整除的时候呢?
附代码:
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int T;
cin >> T;
getchar();
while(T--)
{
char s;
int a, b;
cin >> s >> a >> b;
getchar();
if(s == '+')
cout << a + b << endl;
else if(s == '-')
cout << a - b << endl;
else if(s == '*')
cout << a * b << endl;
else if(s == '/')
{
if(a % b == 0)
cout << a / b << endl; /*整除的时候*/
else
printf("%.2lf\n",(double)a/(double)b);
}
}
return 0;
}