[刷题] PTA 7-40 到底是不是太胖了

程序:

 1 #include<stdio.h>
 2 #include<math.h>
 3 int main() {
 4     int i=0,N;
 5     scanf("%d",&N);
 6     int H[N],W[N];
 7     double P;
 8     for(i=0; i<N; i++) {
 9         scanf("%d %d",&H[i],&W[i]);
10     }
11     for(i=0; i<N; i++) {
12         P = (H[i]-100)*0.9*2;
13         if(fabs(W[i]-P)<0.1*P) {
14             printf("You are wan mei!
");
15         } else if(W[i]>P) {
16             printf("You are tai pang le!
");
17         } else {
18             printf("You are tai shou le!
");
19         }
20     }
21 }

注意两点:

1、因为是浮点数,要用fabs()而不是abs()

2、输入是市斤,判断的时候要转换一下

网友的代码,不用定义数组:

 1 int main(){
 2     int H, W;
 3     int N;
 4     double std;
 5     scanf("%d", &N);
 6     while(N--){
 7         scanf("%d%d", &H, &W);
 8         std = 0.9*(H-100)*2;
 9         if(fabs(std-W)<(0.1*std)){
10             printf("You are wan mei!
");
11         }
12         else if(W>std){
13             printf("You are tai pang le!
");
14         }
15         else{
16             printf("You are tai shou le!
");
17         }
18     }
19 
20 
21     return 0;
22 }

 虽然在控制台显示的是输入一行,输出一行,但可以过,说明判例程序只识别输出

原文地址:https://www.cnblogs.com/cxc1357/p/10729404.html