How to find repeating sequence of characters in a given array?

后端 未结 14 832
故里飘歌
故里飘歌 2020-12-02 12:42

My problem is to find the repeating sequence of characters in the given array. simply, to identify the pattern in which the characters are appearing.

          


        
14条回答
  •  心在旅途
    2020-12-02 12:57

    This is a solution I came up with using the queue, it passed all the test cases of a similar problem in codeforces. Problem No is 745A.

    #include
    using namespace std;
    typedef long long ll;
    
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
    
        string s, s1, s2; cin >> s; queue qu; qu.push(s[0]); bool flag = true; int ind = -1;
        s1 = s.substr(0, s.size() / 2);
        s2 = s.substr(s.size() / 2);
        if(s1 == s2)
        {
            for(int i=0; i qu2 = qu; string str = "";
        while(!qu2.empty())
        {
            cout << qu2.front() << " ";
            str += qu2.front();
            qu2.pop();
        }*/
    
    
        while(!qu.empty())
        {
            if(s[++ind] != qu.front()) {flag = false; break;}
            qu.pop();
        }
        flag == true ? cout << cycle : cout << s.size();
        return 0;
    }
    

提交回复
热议问题