PAT甲级1002水题飘过
Posted findview
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PAT甲级1002水题飘过相关的知识,希望对你有一定的参考价值。
1 #include<iostream> 2 #include<string.h> 3 using namespace std; 4 5 double a[1005]; 6 7 int main() 8 int n1, n2; 9 while(scanf("%d", &n1) != EOF) 10 memset(a, 0, sizeof(a)); 11 for(int i = 1; i <= n1; i++) 12 int x; 13 double y; 14 scanf("%d%lf", &x, &y); 15 a[x] += y; 16 17 scanf("%d", &n2); 18 for(int i = 1; i <= n2; i++) 19 int x; 20 double y; 21 scanf("%d%lf", &x, &y); 22 a[x] += y; 23 24 int cnt = 0; 25 for(int i = 0; i <= 1000; i++) 26 if(a[i] != 0) cnt++; 27 28 printf("%d", cnt); 29 for(int i = 1000; i >= 0; i--) 30 if(a[i] != 0) 31 printf(" %d %.1lf", i, a[i]); 32 33 34 printf("\n"); 35 36 return 0; 37
以上是关于PAT甲级1002水题飘过的主要内容,如果未能解决你的问题,请参考以下文章
PAT 甲级1002 A+B for Polynomials (25)
PAT 甲级 1002 A+B for Polynomials