题目链接:Problem - 1263 (hdu.edu.cn)
解题思路:多组测试数据,输出一个水果昵称,生产地址,个数,他们三个相呼应,所以可以用map的二维应用(map映射map)
其中:map里面会自动排序,输出的时候要选对关键字
#include <iostream>
#include <map>
using namespace std;
int main() {
int t;
cin >> t;
while(t--) {
int n;
cin >> n;
map<string,map<string,int> > mp; // 注意格式
string se[110];
for(int i=0; i<n; i++) {
string a,b;
int c;
cin >> a >> b >> c;
mp[b][a]+=c;
}
for(auto m=mp.begin(); m!=mp.end(); m++) { // 第一个关键字
cout << m->first << endl;
for(auto j=m->second.begin(); j!=m->second.end(); j++) { //第二个关键字
cout<< " |----" << j->first << "(" << j->second << ")"<< endl;
}
}
if(t) cout << endl; // 注意题目输出格式
}
}