1092 最好吃的月饼
思路:
用一个map存储每种月饼的总销量,同时记录最大的销量数。
用迭代器遍历map,当值和最大销量相等时就输出(map按缺省升序,即less<>排序即可)
#include<stdio.h>
#include<iostream>
#include<map>
using namespace std;
map<int, int> mp;
int maxSale = -1; // 记录最大销量
int main(int argc, char* argv[]) {
int n, m; cin >> n >> m;
for (int i = 0; i < m; i++) {
for (int j = 1; j <= n; j++) {
int x; cin >> x;
mp[j] += x;
if (mp[j] >= maxSale) { maxSale = mp[j]; }
}
}
cout << maxSale << endl;
map<int, int>::iterator it;
int cnt = 0;
for (it = mp.begin(); it != mp.end(); ++it) {
if (it->second == maxSale && cnt == 0) { cout << it->first; cnt = 1; }
else if (it->second == maxSale && cnt == 1) { cout << " " << it->first; }
}
return 0;
}