题目描述
求字典序在s1和s2之间的,长度在len1到len2的字符串的个数,结果mod 1000007。
输入描述:
每组数据包涵s1(长度小于100),s2(长度小于100),len1(小于100000),len2(大于len1,小于100000)
输出描述:
输出答案。
输入例子:
ab ce 1 2
输出例子:
56
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
while(scan.hasNext()){
String s1 = scan.next();
String s2 = scan.next();
int len1 = scan.nextInt();
int len2 = scan.nextInt();
int count = 0;
for(int i = len1 ; i <= len2 ; i++){
count += getCount(s1, s2 , i);
}
System.out.println(count - 1);
}
scan.close();
}
public static int getCount(String s1 , String s2 , int len){
int c1_count = 0 ;
int c2_count = 0 ;
int temp = 1;
for(int i = len - 1 ; i >= 0 ; i--){
c1_count += s1.charAt(i) * temp;
c2_count += s2.charAt(i) * temp;
temp *= 26;
}
return c2_count - c1_count;
}
}