提交时间:2022-07-19 11:52:56
运行 ID: 52323
#include <iostream> #define ll long long using namespace std; const int P = 9973; const int MOD = 1000000007; inline int abs(int x) { if(x < 0) return -x; return x; } ll Hash(string s) { ll hash = 0; int n = s.size(); for(int i(0);i < n;i++) hash = (hash * P % MOD + (s[i] - 'a')) % MOD; return hash; } string Move(string s,int step) { int n = s.size(); string sub = s.substr(n - step,step); s.erase(n - step,step); s = sub + s; return s; } int main() { int T; cin>>T; while(T--) { string s,t; int a,b,k,n; ll h1,h2; bool OK = 0; cin>>s>>t>>a>>b; n = s.size(); k = abs(a - b); h1 = Hash(t); for(int i(1);i <= n;i++) { s = Move(s,k); h2 = Hash(s); if(h1 == h2) { OK = 1; cout<<"yes"<<endl; break; } } if(!OK) cout<<"no"<<endl; } return 0; }