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 }
原文地址:https://www.cnblogs.com/findview/p/11632010.html
时间: 2024-10-08 13:47:12