版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_42391248/article/details/84704193
这道题思路很简单,用map容器维护,把原有的字符串放入一个map,然后排完序后的字符串放入另一个map容器。
第一个map容器作用是判断某字符串是否出现过,第二个字符串作用是记录排序后字符串出现的次数。
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;
int main()
{
int n,i;
cin>>n;
map<string,int> mp;
map<string,int> mpp;
for(i=0;i<n;i++)
{
char str[12];
scanf("%s",str);
mpp[str]++;
sort(str,str+strlen(str));
mp[str]++;
}
int q;
cin>>q;
while(q--)
{
char a[12];
scanf("%s",a);
int flag=0;
if(mpp.find(a)!=mpp.end()) flag=-1;
sort(a,a+strlen(a));
if(mp.find(a)!=mp.end()) cout<<mp[a]+flag<<endl;
else cout<<"0"<<endl;
}
}