题目:剪花布条
思路:只将小饰条的首段与花布条各个进行比较,选中其中正确部分在与后面长度进行比较,若全部一样即记录值加一。
import java.util.*;
public class A2087 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in) ;
while(scan.hasNextLine()) {
String n1 = scan.next();
if(n1.charAt(0)=='#')break;
String n2 = scan.next();
int i;
String aa = null;
boolean add = false;
int flag = 0;
for(i=0;i<n1.length();) {
if(n1.length()-i<n2.length()) break;
if(n1.charAt(i) == n2.charAt(0)) {
aa = n1.substring(i,i+n2.length());
add=aa.contentEquals(n2);
}
if(add==false) {
i++;
}else {
add=false;
i+=n2.length();
flag++;
}
}
System.out.println(flag);
}
}
}