标签:
| 描述 |
题目标题: 计算两个字符串的最大公共字串的长度,字符不区分大小写 详细描述: 接口说明 原型: int getCommonStrLength(char * pFirstStr, char * pSecondStr); 输入参数: char * pFirstStr //第一个字符串 char * pSecondStr//第二个字符串
|
|---|---|
| 知识点 | 字符串,查找 |
| 运行时间限制 | 10M |
| 内存限制 | 128 |
| 输入 |
输入两个字符串 |
| 输出 |
输出一个整数 |
| 样例输入 | asdfas werasdfaswer |
| 样例输出 | 6 |
package com.oj5;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Oj {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String data = in.nextLine();
String[] tran = data.split(" ");
String strA = tran[0];
String strB = tran[1];
String dataA = strA.toLowerCase();
String dataB = strB.toLowerCase();
//System.out.println(dataB.substring(1, 7));
int max = 0;
for(int i = 1; i<=dataA.length(); i++){ //设置字串的长度
//System.out.println("长度:"+i);
for(int j = 0;j < dataA.length(); j++){ //设置起始位置
int end = j+i>dataA.length()?dataA.length():j+i;
String temp = dataA.substring(j, end);
if(dataB.contains(temp)&&(end-j)>max){
//System.out.println(temp);
max = end - j;
}
}
}
System.out.println(max);
}
}
标签:
原文地址:http://www.cnblogs.com/lxk2010012997/p/5408608.html