第一次写map的嵌套 和less<>的排序 #include <map> #include <cstdio> #include <iostream> #include <string.h> #include <cstring> #include <string> using namespace std; map<string,map<string,int>,less<string> > a; int main(){ int t,n; char s1[85],s2[85]; scanf("%d",&t); while(t--){ a.clear(); scanf("%d",&n); int k; while(n--){ scanf("%s%s%d",s1,s2,&k); a[s2][s1]+=k; } for(map<string,map<string,int>,less<string> >::iterator ite=a.begin();ite!=a.end();ite++){ cout<<ite->first<<endl;; for(map<string,int>::iterator it=(ite->second).begin();it!=(ite->second).end();it++){ cout<<" |----"<<it->first<<"("<<it->second<<")"<<endl; } } if(t!=0) cout<<endl; } return 0; }
HDU 1263
时间: 2024-10-12 14:26:42