AT水题String Rotation

题目描述

You are given string S and T consisting of lowercase English letters.
Determine if S equals T after rotation.
That is, determine if S equals T after the following operation is performed some number of times:
Operation: Let S=S1S2…S|S|. Change S to S|S|S1S2…S|S|−1.
Here, |X| denotes the length of the string X.

Constraints
·2≤|S|≤100
·|S|=|T|
·S and T consist of lowercase English letters.

输入

Input is given from Standard Input in the following format:
S
T

输出

If S equals T after rotation, print Yes; if it does not, print No.

样例输入

kyoto
tokyo

样例输出

Yes

提示

In the first operation, kyoto becomes okyot.
In the second operation, okyot becomes tokyo.
题意很简单,不过醉翁之意不在酒,想要记录下一种好玩的做法,很好理解。
有关substr函数的应用
附上大佬的链接:
https://blog.csdn.net/Velly_zheng/article/details/89712735?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522158423930019724848339647%2522%252C%2522scm%2522%253A%252220140713.130056874…%2522%257D&request_id=158423930019724848339647&biz_id=0&utm_source=distribute.pc_search_result.none-task

在这里插入图片描述
下面是样例的简单过程:
在这里插入图片描述

#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize (2)
#pragma G++ optimize (2)
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define wuyt main
typedef long long ll;
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > >
template<class T> inline T min(T &x,const T &y){return x>y?y:x;}
template<class T> inline T max(T &x,const T &y){return x<y?y:x;}
//#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();
if(c == '-')Nig = -1,c = getchar();
while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();
return Nig*x;}
#define read read()
const ll inf = 1e15;
const int maxn = 2e5 + 7;
const int mod = 1e9 + 7;
#define start int wuyt()
#define end return 0
start{
    /**
    int num[4];
    cin>>num[1]>>num[2]>>num[3];
    sort(num+1,num+4);
    cout<<num[2]-num[1]+num[3]-num[2];**/
    string s,t;
    cin>>s>>t;
    int ans=0;
    for(int i=0;i<s.size();i++)
    {
        if(s==t) {
            ans=1;
            break;
        }
        s=s.back()+s.substr(0,s.size()-1);
    }
    if(ans==1) printf("Yes\n");
    else printf("No\n");
    end;
}
posted @ 2020-03-16 09:46  PushyTao  阅读(132)  评论(0编辑  收藏  举报