• 典型程序实现代码汇总(1)


    /**
    * 一个词组的单词如果是另一个词组单词的子集,就认为是个borad match,例如对于 "a b c","a", "b c" "c a" "a b c"都匹配,而 "a d"不匹配。
    * 现有一个搜索匹配模块,输入为用户的查询来匹配一个词组字典,找到字典中所有可以和输入broad match的词组,输出预定的词组整型序号。
    * 例如"cheap iphone in china",字典中有 1. "cheap iphone", 2. "cheap mobile", 3 "china iphone"
    * @author Administrator
    *
    */

    package com.org.improve.contact.indexof;
    public class BoradMatch {
    	public static boolean isBoradMatch(String parent, String children){
    		String[] childrenItems=children.split(" ");//以空格为分隔符
    		for (String childrenItem:childrenItems) {
    			if (parent.indexOf(childrenItem)==1) {
    				return false;
    			}
    		}
    		return true;
    	}
       public static void main(String[] args) {
    	 StringBuffer result=new StringBuffer();
    	 String parent="cheap iphone in china";
    	 String [] dicts={"cheap  iphone","cheap mobile","in  china"};
    	 for (int i = 0; i < dicts.length; i++) {
    		if (isBoradMatch(parent,dicts[i])) {
    			result.append(",").append(i+1);
    			
    		}
    	}
    	 if (result.length()>0) {
    		System.out.println("匹配的结果为:"+result.substring(1));
    	} else{
    		System.out.println("无任何匹配结果!");
    	}
    }
    }
    

      

  • 相关阅读:
    第二阶段冲刺01
    第十三周进度总结
    单词统计续
    sys模块
    os模块
    random模块
    datetime模块
    time模块
    模块基础
    内置函数
  • 原文地址:https://www.cnblogs.com/gxbk629/p/4392026.html
Copyright © 2020-2023  润新知