基本流程:
1.利用double数组进行操作,加和后进行简单的计数;
2.进行简单的输出;
注意点:
隐藏的格式输出,注意.1f的格式化输出;
1 #include<iostream> 2 #include<stdlib.h> 3 #include<stdio.h> 4 #include<vector> 5 #include<string> 6 #include<math.h> 7 #include<algorithm> 8 using namespace std; 9 using std::vector; 10 const int maxn = 1002; 11 int main() { 12 double a[maxn]; 13 for (int i = 0; i < maxn; i++) 14 a[i] = 0.0; 15 for (int i = 0; i < 2; i++) { 16 int k; 17 scanf("%d", &k); 18 for (int j = 0; j < k; j++) { 19 int n; 20 double k; 21 scanf("%d %lf", &n, &k); 22 a[n] += k; 23 } 24 } 25 //统计; 26 int cnt = 0; 27 for (int i = 0; i < maxn; i++) { 28 if (a[i] != 0.0) { 29 cnt++; 30 } 31 } 32 cout << cnt; 33 for (int i = maxn - 1; i >= 0; i--) { 34 if (a[i] != 0.0) { 35 printf(" %d %.1lf", i, a[i]); 36 } 37 } 38 system("pause"); 39 return 0; 40 }