题目:https://www.patest.cn/contests/pat-a-PRactise/1047
代码:
#include<cstdio> #include<cstring> #include<cstdlib> #include<cmath>#include<vector>#include<algorithm> using namespace std; vector<int> c[2510];char name[40010][5];bool cmp(int a,int b){ return strcmp(name[a],name[b])<0;}int main() { int n,k,t,cid; scanf("%d%d",&n,&k); for(int i=0;i<n;i++){ scanf("%s %d",name[i],&t); for(int j=0;j<t;j++){ scanf("%d",&cid); c[cid].push_back(i); } } for(int i=1;i<=k;i++){ printf("%d %d/n",i,c[i].size()); sort(c[i].begin(),c[i].end(),cmp); for(int j=0;j<c[i].size();j++){ printf("%s/n",name[c[i][j]]); } } system("pause"); }
新闻热点
疑难解答