hdu2000:
把三个字符按ASCII码排序,昂反正字符也算int型,直接比呗,注意读掉回车就酱水过
1 #include<stdio.h> 2 int main() 3 { 4 char a,b,c,t; 5 while (scanf("%c%c%c",&a,&b,&c)!=EOF) 6 { 7 getchar(); 8 if (a>b) 9 { 10 t=a; 11 a=b; 12 b=t; 13 } 14 if (a>c) 15 { 16 t=a; 17 a=c; 18 c=t; 19 } 20 if (b>c) 21 { 22 t=b; 23 b=c; 24 c=t; 25 } 26 printf("%c %c %c\n",a,b,c); 27 } 28 return 0; 29 }
hdu2001:
计算两点间距离,注意读入的数据就是浮点型了,水过
1 #include<stdio.h> 2 #include<math.h> 3 int main() 4 { 5 double x1,y1,x2,y2,d; 6 while (scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2)!=EOF) 7 { 8 d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); 9 printf("%.2lf\n",d); 10 } 11 return 0; 12 }
hdu2002:
计算球体积,公式水过就好。
1 #include<stdio.h> 2 #define PI 3.1415927 3 int main() 4 { 5 double r,v; 6 while (scanf("%lf",&r)!=EOF) 7 { 8 v=4*PI*r*r*r/3; 9 printf("%.3lf\n",v); 10 } 11 return 0; 12 }
hdu2003:
求绝对值,注意读入是浮点型,之后用函数也好用我那时候用的土办法也好,水过就好~
1 #include<stdio.h> 2 int main() 3 { 4 double a; 5 while (scanf("%lf",&a)!=EOF) 6 { 7 if (a>=0) printf("%.2lf\n",a); 8 else printf("%.2lf\n",-a); 9 } 10 return 0; 11 }
hdu2004:
成绩转换,六个if水过,出题人你开心就好```
1 #include<stdio.h> 2 int main() 3 { 4 int t; 5 while (scanf("%d",&t)!=EOF) 6 { 7 if (90<=t&&t<=100) printf("A\n"); 8 if (80<=t&&t<=89) printf("B\n"); 9 if (70<=t&&t<=79) printf("C\n"); 10 if (60<=t&&t<=69) printf("D\n"); 11 if (0<=t&&t<=59) printf("E\n"); 12 if (100<t||t<0) printf("Score is error!\n"); 13 } 14 return 0; 15 }
浙公网安备 33010602011771号