PAT B1032

总结

1:使用const int maxn

2:num[maxn]将下标与存储数据结合

#include<iostream>
#include<cstdio>
using namespace std;
const int maxn = 100010;
int main() {
	int tem;
	int n, max = -1, maxi = 0, num[maxn] = { 0 };
	scanf("%d",&n);
	for (int i = 1; i <= n; i++) {
		int a,b;
		scanf("%d %d",&a,&b);
		num[a] += b;
	}
	for (int i = 1; i < maxn; i++) {
		if (num[i] != 0) {
			if (num[i] > max)
			{
				max = num[i];
				maxi = i;
			}
		}
	}
	printf("%d %d", maxi,max);
	cin >> tem;
	return 0;
}

 

上一篇:IP地址


下一篇:216、递增顺序查找树