典型程序实现代码汇总(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("无任何匹配结果!");
	}
}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值