其他分享
首页 > 其他分享> > PAT 甲级 A1002 (2019/01/30)

PAT 甲级 A1002 (2019/01/30)

作者:互联网

 1 #include<cstdio>
 2 const int MAXN = 1001;
 3 double sum[MAXN];
 4 int main(){
 5     int exp, n, count = 0;    //次数 
 6     double coe;                      //系数 
 7     scanf("%d",&n);
 8     for(int i = 0; i < n; i++){
 9         scanf("%d %lf", &exp, &coe);  //下标存次数,value存系数
10         sum[exp] += coe;         
11     }
12     scanf("%d",&n);
13     for(int i = 0; i < n; i++){
14         scanf("%d %lf", &exp, &coe); //下标存次数,value存系数
15         sum[exp] += coe;     
16     }
17     for(int i = 0; i < MAXN; i++){
18         if(sum[i] != 0)
19             count++;
20     }
21     printf("%d",count);
22     for(int i = MAXN; i >= 0; i--)
23         if(sum[i] != 0) printf(" %d %.1f", i, sum[i]);
24     return 0;
25 } 

 

标签:01,PAT,int,sum,30,++,coe,exp,MAXN
来源: https://www.cnblogs.com/zjsaipplp/p/10415760.html