map可以映射map……
然后在map里面会自己排序
惊了
注意输出格式 回车的输出
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <queue> #include <algorithm> #include <string> #include <map> using namespace std; map<string, map<string, int> > mp; int main() { int T; cin >> T; while(T--) { int n; cin >> n; mp.clear(); string place, fruit; int num; for(int i = 0; i < n; i++) { cin >> fruit >> place >> num; mp[place][fruit] += num; } for(map<string, map<string, int> >::iterator iter1 = mp.begin(); iter1 != mp.end(); iter1++) { cout << iter1 -> first << endl; for(map<string, int>::iterator iter2 = iter1->second.begin(); iter2 != iter1->second.end(); iter2++) { cout << " |----" << iter2->first << "(" << iter2->second << ")" << endl; } } if(T) cout << endl; } return 0; }