문장에서 단어를 빨리 찾다
2062 단어 쾌속
public class WordsFinder {
/**
* word text
* @Date: 2013-6-14 05:57:19
* @Description: int
* @param word
* @param text
* @return
*/
public static int count(String word,String text){
char[]w = word.toCharArray();
char[]t = text.toCharArray();
int size = w.length;
// List<String> list = new ArrayList<String>();
int sum = 0;
for (int i = 0; i < t.length; i++) {
if(w[0]==t[i]){
if(i+size-1<t.length){
boolean bool = true;
for (int j = 1; j < size; j++) {
bool&=(w[j]==t[i+j]);
if(!bool){
break;
}
}
if(bool){
sum++;
}
}
}
}
return sum;
}
/**
* text list ,
* @Date: 2013-6-27 02:57:28
* @Description: Set<String>
* @param list
* @param text
* @return
*/
public static Set<String> seek(List<String> list,String text){
Set<String> words = new HashSet<String>(list);
Set<String> set = new HashSet<String>();
for (String word : words) {
int sum = count(word, text);
if(sum>0){
set.add(word);
}
}
return set;
}
/**
* text list ,
* @Date: 2013-6-27 02:57:33
* @Description: Map<String,Integer>
* @param list
* @param text
* @return
*/
public static Map<String,Integer> seekCount(List<String> list,String text){
Set<String> words = new HashSet<String>(list);
Map<String,Integer> map = new HashMap<String, Integer>();
for (String word : words) {
int sum = count(word, text);
if(sum>0){
map.put(word, sum);
}
}
return map;
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
문장에서 단어를 빨리 찾다텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.