http://acm.hdu.edu.cn/showproblem.php?pid=2061
有些输入的小技巧
3036655 | 2010-10-05 15:47:58 | Accepted | 2061 | 15MS | 176K | 663 B | G++ |
2061
1 #include<stdio.h>
2 #include<string.h>
3 #include<stdlib.h>
4 #define max(x,y) (x)>(y)?x:y
5 #define min(x,y) (x)<(y)?x:y
6 #define N 10001
7 int main()
8 {
9 int i,ncase,flag,n,j;
10 double count,sum,c,s,GPA;
11 while(scanf("%d",&ncase)!=EOF)
12 {
13 for(i=1;i<=ncase;i++)
14 {
15 scanf("%d",&n);
16 flag=0;count=sum=0;
17 getchar();
18 for(j=0;j<n;j++)
19 {
20 scanf("%*s %lf%lf", &c,&s);//小技巧
21 sum+=c*s;
22 count+=c;
23 if(s<60&&s>=0)flag=1;
24 }
25 if(flag==1)
26 {
27 printf("Sorry!\n");
28 }
29 else
30 {
31 GPA=sum/count;
32 printf("%.2f\n",GPA);
33 }
34 if(i<ncase)putchar('\n');//注意题目要求有一空行
35 }
36 }
37 return 0;
38 }
39