前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >华为測试 公共子串计算

华为測试 公共子串计算

作者头像
全栈程序员站长
发布2022-07-11 09:51:14
1180
发布2022-07-11 09:51:14
举报

大家好,又见面了,我是全栈君。

题目标题:

计算两个字符串的最大公共字串的长度,字符不区分大写和小写

输入两个字符串

输出一个整数

案例输入:asdfas werasdfaswer

案例输出:6

代码语言:javascript
复制
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string str1,str2,temp;
	int m,MaxNum=0,Len;
	cin>>str1>>str2;
	string::size_type index1;
	string::size_type index2;
	for(index1=0;index1!=str1.size();++index1)
	{
		str1[index1]=tolower(str1[index1]);
	}
	for(index2=0;index2!=str2.size();++index2)
	{
		str2[index2]=tolower(str2[index2]);
	}
	for(int j=1;j<=str1.size();++j)
	{
		for(int i=0;i!=str1.size();++i)
		{
			if(i+j<=str1.size())
			{
				temp=str1.substr(i,j);
				m=str2.find(temp);
				if(m!=string::npos)
				{
					Len=temp.size();
					if(Len>MaxNum)
						MaxNum=Len;
				}

			}
		}
	}
	cout<<MaxNum;
	return 0;
}

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/115209.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年2月7,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档