有人bangbang我吗,注意题目要求挑出的字母要成环。用c写

img

img


#include <cstring>
#include <iostream>

using namespace std;

string x;
string word;
int op[200010] = {0};
int lenx;
int lenword;

int main()
{
    //freopen("E://test.txt", "r", stdin);
    cin >> x >> word;
    lenx = x.length();
    lenword = word.length();
    string words = word + word + word;
    //cout << words << endl;

    for (int i = 0; i < lenword; i++)
    {//用i来循环所有单词的组合
        string tmpword(words, i + lenword *5/6, lenword);
        int k = 0;
        for (int j = 0; j < lenx; j++)
        {//用j来循环x中的每一个字符
            if (x[j] == tmpword[k])
            {//如果存在相同的情况
                op[j] = 1;//留下标记
                k++;
            }
            if (k == lenword)
            {//找到结果了,因为k长度与单词长度一样了
                int r = 0;
                for (int p = 0; p < lenx; p++)
                {
                    if (op[p] == 1)
                    {
                        cout << p + 1;
                        if (r < lenword - 1)
                        {
                            cout << " ";
                        }
                        r++;
                    }
                }
                cout << endl;
                return 0;
            }
        }
        memset(op, 0, sizeof(op));
    }
    return 0;
}