//
// main.cpp
// PATA1002
//
// Created by Phoenix on 2018/1/30.
// Copyright © 2018年 Phoenix. All rights reserved.
//
#include <iostream>
#include <cstdio>
const int maxn = 1010;
double num[maxn] = {0};
double a[25][2];
int main(int argc, const char * argv[]) {
int n;
scanf("%d", &n);
for(int i = 0; i < n; i++) {
int m;
double k;
scanf("%d %lf", &m, &k);
num[m] += k;
}
scanf("%d", &n);
for(int i = 0; i < n; i++) {
int m;
double k;
scanf("%d %lf", &m, &k);
num[m] += k;
}
int cnt = 0;
for(int i = maxn - 1; i >= 0; i--){
if(num[i] != 0) {
a[cnt][0] = i;
a[cnt][1] = num[i];
cnt++;
}
}
printf("%d", cnt);
for(int i = 0; i < cnt; i++) {
printf(" %.0f %.1f", a[i][0], a[i][1]);
}
return 0;
}
哈希映射法
PATA1002题解
最新推荐文章于 2022-11-11 12:27:48 发布