码迷,mamicode.com
首页 > 编程语言 > 详细

字符串c++字符环

时间:2018-06-28 21:11:39      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:ret   cpp   int   i++   题目   amp   clu   algo   turn   

     今天这个题目及其难。还好靠身边的丁冠宇大佬帮忙,最后还是把这道题给搞出来了!!!

这里给大家分享一下。希望能帮助到各位。

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
    int x, y, len, len1, len2, limit, ans=0;
    string s1, s2;
    cin >> s1 >> s2;
    len1 = s1.size();
    len2 = s2.size();
    limit = min(len1, len2);
    s1 += s1; // 造环
    s2 += s2; // 造环
    for (int i=0; i<len1; i++){
        for (int j=0; j<len2; j++){
            len = 0;
            x = i;
            y = j;
            while (s1[x++]==s2[y++] && len<limit) len++;
            if (len > ans) ans = len;
        }
    }
    cout << ans << endl;
    return 0;
}

  

字符串c++字符环

标签:ret   cpp   int   i++   题目   amp   clu   algo   turn   

原文地址:https://www.cnblogs.com/5t2y0/p/9240582.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!