题目链接:点击打开链接
题目大意:略。
解题思路:此题主要卡 scnaf / cin;+ STL的搭配使用;不能用 map<char*, int> 替代 map<string, int>,一般情况认为 char* 和 string 效果通用,但是在这里不是一回事了。指针毕竟还是指针。我们可以用 char[ ] 输入直接放到 map[ ] 里,底层会自动转换成 string。
AC 代码
#include<bits/stdc++.h>
#include<cmath>
#define mem(a,b) memset(a,b,sizeof a);
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
struct cmp
{
bool operator()(int a,int b)
{
return a>b;
}
};
priority_queue<int,vector<int>,cmp> pq,tpq;
map<string,priority_queue<int,vector<int>,cmp> > mp;
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
mp.clear();
int id,k;
char name[7];
for(int i=0;i<m;i++)
{
scanf("%d%d",&id,&k);
for(int j=0;j<k;j++)
{
scanf("%s",name);
mp[name].push(id);
}
}
for(int i=0;i<n;i++)
{
scanf("%s",name);
tpq=mp[name];
printf("%s",name);
printf(" %d",tpq.size());
while(!tpq.empty())
{
printf(" %d",tpq.top());
tpq.pop();
}
puts("");
}
}
return 0;
}