zoukankan      html  css  js  c++  java
  • 公共字串计算

    描述

    题目标题:

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

    详细描述:

    接口说明

    原型:

    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);
    	}
    }
    

      

  • 相关阅读:
    困勉而行
    6.12
    js 实现表格筛选不请求后台数据
    VUE方法和函数汇总
    sql isnull用法
    js forEach的用法
    js _this.$nextTick 解决页面渲染问题
    element table 复选框单选
    js attr 追加属性
    C# 过滤器 验证页面权限
  • 原文地址:https://www.cnblogs.com/lxk2010012997/p/5408608.html
Copyright © 2011-2022 走看看