公共字串计算
2016-04-19 16:06
134 查看
描述 | 题目标题: 计算两个字符串的最大公共字串的长度,字符不区分大小写 详细描述: 接口说明 原型: 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); } }
相关文章推荐
- passing argument 3 of ‘wtk_hlv_rec_init’ discards ‘const’ qualifier from pointer target type
- winhex使用经验
- mysql常用几个操作记录
- 自定义横向Progressbar
- 6--队列
- 男人>女人
- 又拍云异步上传实例教程详解
- linux 中文乱码
- Java基础之class文件介绍(基础)
- 安卓小经验积累
- Android驱动入门系列(一)
- JVM学习笔记(一)
- 混淆类别(主题)判别技术(更新完善)
- 一个练习打字的网站
- memset memcpy函数
- AppCompatActivity
- SE Springer小组《Spring音乐播放器》软件需求说明3
- java实现一个简单TCPSocket聊天室功能分享
- acm 2 1017 非常可乐
- zzulioj--1874--蛤玮学计网(模拟)