PAT 甲級 A1002 (2019/01/30)
阿新 • • 發佈:2019-02-22
class col double n) ++ spa ons bsp print
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 }
PAT 甲級 A1002 (2019/01/30)