B. Reverse String(brute force)
给的范围小,数据水,暴搜
为什么说数据水? 对于每个字母,直接往后搜到最后一个就行,不用管到第一个后返回从第二个开始。
例如
abcddd
abab
答案搜不到,数据也不给这样类型的
回去读题目,发现题目读错了。
往右走几步,然后往左几步,没有说来回反复多次往返。
这样代码就简单了
// Problem: B. Reverse String
// Contest: Codeforces - Harbour.Space Scholarship Contest 2021-2022 (open for everyone, rated, Div. 1 + Div. 2)
// URL: https://codeforces.com/problemset/problem/1553/B
// Memory Limit: 256 MB
// Time Limit: 3000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stack>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<sstream>
#include<cassert>
#include<bitset>
#include<list>
#include<unordered_map>
using namespace std;
#define lowbit(x) (x&-x)
#define dbg(x) cout << #x << " = " << x << endl
#define rep(i,l,r) for(int i = l; i <= r; i++)
typedef long long ll;
//const int N=1000*500+100;
char a[505], b[1100];
void solve()
{
cin >> (a+1);
cin >> (b+1);
int n = strlen(a+1);
int m = strlen(b+1);
bool f = false;
rep(i,1,n)
{
if(a[i] == b[1])
{
int pos = 1;
for(int j=i; pos<=m&&j<=n ;j++,pos++)
{
if(a[j] != b[pos]) break;
for(int l=j,k=pos; l>=1&&k<=m;l--,k++)
{
if(k==m&&b[k]==a[l])
{
f = true;
break;
}
if(a[l]!=b[k]) break;
}
}
}
}
if(f) puts("YES");
else puts("NO");
}
int main()
{
ios::sync_with_stdio(false);cin.tie(0);
int Case;cin >> Case;
while(Case--)
solve();
return 0;
}
还没有评论,来说两句吧...