zoukankan      html  css  js  c++  java
  • 字符串旋转

        Problem Statement

    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 = S_1 S_2 ... S_{|S|}. Change S to S_{|S|} S_1 S_2 ... S_{|S|-1}.

    Here, |X| denotes the length of the string X.

    Constraints

    • 2 leq |S| leq 100
    • |S| = |T|
    • S and T consist of lowercase English letters.

    Input

    Input is given from Standard Input in the following format:

    S
    T
    

    Output

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

    Sample Input 1

    kyoto
    tokyo
    

    Sample Output 1

    Yes
    
    • In the first operation, kyoto becomes okyot.
    • In the second operation, okyot becomes tokyo.

    Sample Input 2

    abc
    arc
    

    Sample Output 2

    No
    

    abc does not equal arc after any number of operations.

    Sample Input 3

    aaaaaaaaaaaaaaab
    aaaaaaaaaaaaaaab
    

    Sample Output 3

    Yes

    利用string类型的几个函数即可

    size()   resize()   insert()

      string S, T;
        cin >> S >> T;
        int count = S.size();
        int flag = 0;
        while (count--)
        {
            if (S == T)
            {
                flag = 1;
                break;
            }
            S.insert(0," ");//S.size增加了1
            S[0]=S[S.size() - 1];//最后一个字符复制到第一个
            S.resize(S.size()-1);//调整S.size,将最后的字符去掉
        }
        if(flag)
            cout << "Yes";
        else
            cout << "No";

  • 相关阅读:
    解决点击状态栏时ScrollView自动滚动到初始位置失效办法
    如何设计用户、角色、权限表
    Subject的功能
    shiro授权的源码分析
    shiro之认证源码分析
    shiro配置
    JSONArray转JSONObject
    parameterType
    MyBatis:Parameter Maps collection does not contain value for 的问题解决
    mybatis报ORA-00911: 无效字符
  • 原文地址:https://www.cnblogs.com/lxzbky/p/10553038.html
Copyright © 2011-2022 走看看