现在的位置: 首页 > 综合 > 正文

HDU 2089 不要62

2013年07月28日 ⁄ 综合 ⁄ 共 1349字 ⁄ 字号 评论关闭

不要62

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13615    Accepted Submission(s): 4369


Problem Description
杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer)。
杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客的心理障碍,更安全地服务大众。
不吉利的数字为所有含有4或62的号码。例如:
62315 73418 88914
都属于不吉利号码。但是,61152虽然含有6和2,但不是62连号,所以不属于不吉利数字之列。
你的任务是,对于每次给出的一个牌照区间号,推断出交管局今次又要实际上给多少辆新的士车上牌照了。
 


Input
输入的都是整数对n、m(0<n≤m<1000000),如果遇到都是0的整数对,则输入结束。
 


Output
对于每个整数对,输出一个不含有不吉利数字的统计个数,该数值占一行位置。
 


Sample Input
1 100 0 0
 


Sample Output
80
 


Author
qianneng
 


Source
 

 

import java.io.*;
import java.util.*;
public class Main {
	int a[]=new int[1000010];
	int n,m;
	public static void main(String[] args) throws IOException{
		new Main().work();
	}
	void work() throws IOException{
		BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw=new PrintWriter(new OutputStreamWriter(System.out),true);
		init();
		String s[]=bu.readLine().split(" ");
		n=Integer.parseInt(s[0]);
		m=Integer.parseInt(s[1]);
		while(n!=0&&m!=0){
			int count=m-n+1;//共有多少个数字
			for(int i=n;i<=m;i++){
				if(a[i]==1)
					count--;// 去除包含 不吉利数字
			}
			pw.println(count);
			s=bu.readLine().split(" ");
			n=Integer.parseInt(s[0]);
			m=Integer.parseInt(s[1]);
		}
	}
	//初始化
	void init(){
		for(int i=0;i<a.length;i++){
			if(boo1(i)) a[i]=1;
		}
	}
	
	//判断是否包含不吉利数字
	boolean boo1(int x){
		String s=String.valueOf(x);
		if(s.contains("4"))
			return true;
		if(s.contains("62"))
			return true;
		return false;
	}
}

 

抱歉!评论已关闭.