题目
传送门
Input 2 welcome toparticipate inthe ccpccontest inharbin inoctober harvest belong ninja reset amazing intriguing Output No Yes
题意:t组样例,每组六个字符串,问是否能分别从六个字符串中各挑出一个字母组成单词“harbin”
思路:我们可以先标记一下每个字符串中出现过哪个字符,然后直接用全排列函数判断串中是否含有该有的字符即可
AC code
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<sstream>
#include<stack>
#include<queue>
using namespace std
;
char b
[2600000];
void solve()
{
int vis
[6][30];
memset(vis
,0,sizeof(vis
));
char a
[]="harbin";
for(int i
=0;i
<6;i
++)
{
cin
>>b
;
int k
=strlen(b
);
for(int j
=0;j
<k
;j
++)
vis
[i
][b
[j
]-'a']=1;
}
sort(a
,a
+6);
int flag
=0;
do
{int flagg
=1;
for(int i
=0;i
<6;i
++)
if(vis
[i
][a
[i
]-'a']==0)
{
flagg
=0;
break;
}
if(flagg
)
{
flag
=1;
break;
}
}while(next_permutation(a
,a
+6));
if(flag
)printf("Yes\n");
else printf("No\n");
}
int main()
{
ios
::sync_with_stdio(0);
int t
;
cin
>>t
;
while(t
--)
{
solve();
}
}