0
点赞
收藏
分享

微信扫一扫

两个字符串


两个字符串

Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 26   Accepted Submission(s) : 11

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

Problem Description


给出两个字符串A和B,判断是否有存在一个子串既出现在A中又出现在B中。


Input


第一行为一个整数T,表示测试数据组数
接着T组测试数据,每组测试数据包含两行,每行一个字符串(仅由字母组成)。
字符串长度不超过10^5


Output


对于每组测试数据,如果存在符合条件的子串,输出YES, 否则输出No


Sample Input


2 hello world hi world


Sample Output


YES No


#include<cstdio>
#include<cstring>
int main()
{
int a[200],i,T,ok=0;
char s1[100002],s2[100002];
scanf("%d",&T);
while(T--)
{
memset(a,0,sizeof(a));
scanf("%s",s1);
scanf("%s",s2);
for(i=0; i<strlen(s1); i++)
{
a[s1[i]-'A']++;
}
for(i=0,ok=0; i<strlen(s2); i++)
{
if(a[s2[i]-'A']>0)
{
ok=1;
break;
}
}
if(ok)
{
printf("YES\n");
}
else printf("No\n");
}
return 0;
}





























举报

相关推荐

0 条评论