匹配最大字符串
来源:互联网 发布:淘宝刷客究竟犯不犯法 编辑:程序博客网 时间:2024/06/05 05:56
从键盘输入两个字符串,获取两个字符串中匹配度最高的部分(即:两个字符串中最长的相同字符串)
如:
输入:
13,10,'match','$'
13,10,'No match','$'
输出:
13,10,'
代码:
package 匹配最大字符串;
import java.util.Scanner;
public class FindTheLargestString {
public static String findthelargeststring (String string1,String string2)
{
int i,j,k;
String string="";
int max=0;
for(i=0;i<string1.length();i++)
{
int index=i;
for(j=0;j<string2.length();j++)
{
String temp="";
int tempLength=0;
for(k=j;k<string2.length()&&index<string1.length();k++)
{
if(string1.charAt(index)==string2.charAt(k))
{
temp+=string1.charAt(index);//将相同的元素添加到临时的字符串temp中
tempLength++;
index++;
}
else
{
break;
}
}
if(max<tempLength)//用于获取匹配度最高的字符串
{
max=tempLength;
string=temp;
}
}
}
return string;
}
public static void main(String []args)
{
String a,b;
Scanner s1 = new Scanner (System.in);
Scanner s2 = new Scanner (System.in);
System.out.print("Please Input the string1:");
a=s1.next();
System.out.print("Please Input the string2:");
b=s2.next();
System.out.println(findthelargeststring(a,b));
}
}
- 匹配最大字符串
- 字符串最大匹配长度
- 字符串的最大匹配问题
- 字符串的最大相似匹配
- 两个字符串中匹配最大字符串
- 两个字符串中匹配最大字符串
- 二字符串匹配字串最大长度
- 求字符串可匹配的最大长度
- 匹配两个字符串的最大子串
- java获取两个字符串中的最大匹配
- 最大匹配
- 基于STL的字符串最大长度匹配算法
- 完全匹配-最大匹配
- java实现字符串匹配问题之求两个字符串的最大公共子串
- 字符串匹配
- 字符串匹配
- 字符串匹配
- 字符串匹配
- poj 3625 Building Roads(图论:最小生成树)
- gridview使用总结
- HDU 4864(Task)
- starling 学习(二)配置过程
- 从用python做zoj1011发生Non-zero Exit Code错误说起
- 匹配最大字符串
- 10.2.0.1.1 grid control的启动和关闭
- 选择,冒泡排序
- 使用Label控件直接显示并更新时间
- capturing self strongly in this block is likely to lead to a retain cycle
- VIM中的搜索和替换
- typename的正确使用
- STL学习(七)remove_if 学习
- mac终端命令大全介绍