为啥wa了呀, 调了好久没看出来
查看原帖
为啥wa了呀, 调了好久没看出来
1226563
Qi_jB楼主2024/4/20 10:05
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>

using namespace std;
const int N = 100005;
char s[15];
string  s1 , s2 ; 

bool f(int x)
{
	int ans = 0 ; 
	int i = 0 ; 
	while(s1[x] == s2[i] && x < s1.size() && i < s2.size())
	{
		x ++ , i ++ ; 
		ans ++ ; 
	}
	if(ans == s2.size()) return true;
	x -= 2 ; 
	
	while(s1[x] == s2[i] && x >= 0 && i < s2.size())
	{
		x -- , i ++ ;
		ans ++ ;  
	}
	
	if(ans == s2.size()) return true;
}
void solve()
{
	cin >> s1 >> s2 ; 
	int cnt = 0 ; 
	for(int i = 0 ; i  < s1.size() ; i ++ )
	{
		if(s1[i] == s2[0])
		{
			if(f(i)) cnt = 1 ; 
		}
	}
	if(cnt > 0 ) printf("YES\n");
	else printf("NO\n");
}
int main()
{
	int t ; 
	cin >> t ; 
	while( t -- ) 
	{
		solve();
	}
	return 0 ; 
}
2024/4/20 10:05
加载中...