import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String str1 = sc.next();
String str2 = sc.next();
int count = 0;
for(int i = 0; i <= str1.length() - str2.length();){
if(str1.substring(i, i + str2.length()).equals(str2)){
count++;
i += str2.length();
}else{
i++;
}
}
System.out.println(count);
}
}
}
substring 的用法
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int from = sc.nextInt();
int to = sc.nextInt();
long count = 0;
long[] fib = new long[80];
fib[0] = 1;
fib[1] = 1;
for(int i = 2; i < 80; i++){
fib[i] = fib[i - 1] + fib[i - 2];
}
for(int i = from - 1; i <= to - 1; i++){
count += fib[i];
}
System.out.println(count);
}
}
}
关于斐波那契数列
|