Album: Quỳnh

public class SearchTool {<br /> <br /> /**<br /> * @param args the command line arguments<br /> */<br /> public static void main(String[] args) {<br /> // TODO code application logic here<br /> String[] a = {&quot;Java Development in thinking Ricky Martin&quot;,&quot;Virtual Piano Guide Nguyen Van Vinh&quot;,<br /> &quot;Nhung noi kho tai Samsung Luu Matin&quot;,&quot;Nhung cach lam giau nhanh nhat Nguyen Van Tho&quot;,<br /> &quot;Android Development Lee Kun Hee&quot;,&quot;How to apply in samsung Lee Kun Hee&quot;};<br /> SearchTool se = new SearchTool();<br /> for(int i=0;i&lt;a.length;i++){<br /> System.out.println(a[i]+&quot; : &quot;+se.compare(&quot;guidde&quot;, a[i]));<br /> }<br /> }<br /> <br /> public double compare(String target, String source){<br /> target = target.toUpperCase();<br /> source = source.toUpperCase();<br /> double score = 0;<br /> int count=0;<br /> if(source.contains(target)){<br /> score=10;<br /> }<br /> else{<br /> for(int i=0;i&lt;target.length();i++){<br /> source = source.replaceAll(target.charAt(i)+&quot;&quot;, &quot;@&quot;);<br /> }<br /> int first=0;<br /> int dis = 0;<br /> if(source.contains(&quot;*&quot;)){<br /> first = source.indexOf(&quot;@&quot;);<br /> source = source.replaceFirst(&quot;@&quot;, &quot;&quot;);<br /> count++;<br /> }<br /> while(source.contains(&quot;@&quot;)){<br /> int a = source.indexOf(&quot;@&quot;);<br /> dis+= a-first;<br /> first=a;<br /> source = source.replaceFirst(&quot;@&quot;, &quot;&quot;);<br /> count++;<br /> }<br /> score = (double)count/(double)dis;<br /> }<br /> <br /> return score;<br /> }<br /> <br /> <br /> }[/i][/i]

Quỳnh

Đã cập nhât 9/2/15
21176  
20944  
20945  
20946  
20947  
Đang tải dữ liệu......
Đang tải dữ liệu......
vanvinhbk
public class SearchTool {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
String[] a = {"Java Development in thinking Ricky Martin","Virtual Piano Guide Nguyen Van Vinh",
"Nhung noi kho tai Samsung Luu Matin","Nhung cach lam giau nhanh nhat Nguyen Van Tho",
"Android Development Lee Kun Hee","How to apply in samsung Lee Kun Hee"};
SearchTool se = new SearchTool();
for(int i=0;i<a.length;i++){
System.out.println(a[i]+" : "+se.compare("guidde", a[i]));
}
}

public double compare(String target, String source){
target = target.toUpperCase();
source = source.toUpperCase();
double score = 0;
int count=0;
if(source.contains(target)){
score=10;
}
else{
for(int i=0;i<target.length();i++){
source = source.replaceAll(target.charAt(i)+"", "@");
}
int first=0;
int dis = 0;
if(source.contains("*")){
first = source.indexOf("@");
source = source.replaceFirst("@", "");
count++;
}
while(source.contains("@")){
int a = source.indexOf("@");
dis+= a-first;
first=a;
source = source.replaceFirst("@", "");
count++;
}
score = (double)count/(double)dis;
}

return score;
}


}[/i][/i]
  1. Phuhuu_vp thích nội dung này.

Công cụ