华为机试---字符串计数
来源:互联网 发布:avmoon新域名 编辑:程序博客网 时间:2024/05/17 03:03
题目描述
求字典序在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;
}
}
- 华为机试---字符串计数
- 华为机试—单词计数
- 华为机试—单词计数
- 华为机试---字符串过滤
- 华为机试:字符串系列
- 华为机试---字符串过滤
- 华为机试:查找字符串
- 华为机试--字符串加密
- 华为机试--字符串排序
- 华为机试---字符串通配符
- 华为机试---字符串匹配
- 华为机试---字符串替换
- 华为机试 字符串分隔
- 华为机试-字符串排序
- 华为机试-字符串加密
- 华为机试-字符串合并
- 华为机试-字符串加密
- 【华为机试】字符串分隔
- the application is not licensed to create or modify schema for this type of data
- Django(三)后台
- office2007显示隐藏文字。
- new Integer(1)和Integer.valueOf(1)的区别
- block没那么难(二):block和变量的内存管理
- 华为机试---字符串计数
- 串口发数据到PIXHAW,PIXHAW发数据到地面站
- SEO随笔
- EDIUS字幕窗口中保存和自动另存为该怎样区分
- Android中Textview显示带html文本二-------【Textview显示本地图片】
- 合并两个排序的链表
- block没那么难(三):block和对象的内存管理
- Java构造方法中:带参的构造方和和不带参数的构造方法
- 归类总结