showcase


私信TA

用户名:1314xcx

访问量:19413

签 名:

等  级
排  名 154
经  验 7058
参赛次数 1
文章发表 70
年  龄 0
在职情况 学生
学  校 霍格沃斯-斯莱特林学院
专  业 计算机科学与技术

  自我简介:

解题思路:

思路很简单,把密码中所能形成的子串都判断一遍。

注意事项:没什么需要特别注意的,我写函数时用了不少变量,太容易弄混了。

参考代码:

#include<iostream>
#include<string>
using namespace std;
int f(string s)
{
	int length=s.length(),max=1;
	for(int i=0;i<length;i++)
	{
		for(int j=length-1;j>i;j--)
		{		
			int count=1;
			for(int start=i,end=j;;start++,count++,end--)
			{
				if(s[start]!=s[end])
				break;
				if(count==(j-i+1)/2)
				{
					if(max<(j-i+1))
					 max=j-i+1;
				} 
			}
    	}
    }
	return max;
}
int main()
{
	string str;
	while(cin>>str)
	 cout<<f(str)<<endl;
	return 0;
 }


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区