题目大意:求12个数的平均数,没有末尾0
啊,WA到怀疑人生啊……
代码都贴上,大家感受一下……
AC代码:
int main() {
int T; cin>>T;
while (T--) {
double sum=0;
for (int i=0; i<12; ++i) {
double n;
cin>>n;
sum+=n;
}
sum/=12;
int tmp=(sum+0.005)*100;
if (tmp%100==0) {
printf ("$%.0f\n",sum);
} else if (tmp%10==0) {
printf ("$%.1f\n",sum);
} else printf ("$%.2f\n",sum);
}
return 0;
}
WA代码:
int main() {
int T; cin>>T;
while (T--) {
double sum=0;
for (int i=0; i<12; ++i) {
double n;
cin>>n;
sum+=n;
}
sum/=12;
sum+=0.005;
int tmp=sum*100;
if (tmp%100==0) {
printf ("$%.0f\n",sum);
} else if (tmp%10==0) {
printf ("$%.1f\n",sum);
} else printf ("$%.2f\n",sum);
}
return 0;
}