HDOJ.2089 不要62

不要62

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

Problem Description

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

Input

输入的都是整数对n、m(0

Output

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

Sample Input

1 100
0 0

Sample Output

80

题意分析

数字的处理,输出有点麻烦,想了半天,不知各位有什么简单办法

代码总览

/*
    Title:HDOJ.2089
    Author:pengwill
    Date:2016-11-14
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define max  1000005
int a[2][max];

int main()
{
    //memset(a,0,sizeof(a));
    int sta,end,i,temp,k1,k2,cnt = 0,judge;
        for(i = 1;i<=max;++i){
            //a[i] = 0;
            judge = 0;
            k1 = k2 = 0;
            temp = i;
            while(temp){
                k2 = k1;
                k1 = temp % 10;
                temp = temp / 10;
                if(k1 == 4){
                    //a[i] = 1;
                    judge = 1;
                    break;
                }else if(k1==6 && k2 ==2){
                    //a[i] = 1;
                    judge = 1;
                    break;
                }
            }
            if(!judge){
                a[0][i] = ++cnt;
                a[1][i] = 0;
            }else{
                a[0][i] = cnt;
                a[1][i] = 1;
            }
        }
    while(scanf("%d%d",&sta,&end) && (sta || end)){
        //printf("%d\t%d\n",a[0][sta],a[0][end]);
        if((!a[1][sta]&&!a[1][end])){
            printf("%d\n",a[0][end]-a[0][sta]+1);
        }else if(!a[1][sta] && a[1][end]){
            printf("%d\n",a[0][end]-a[0][sta]+1);
        }else if(a[1][sta] && a[1][end] || (a[1][sta] && !a[1][end])){
            printf("%d\n",a[0][end]-a[0][sta]);
        }


    }
    return 0;
}
posted @ 2016-11-14 11:37  pengwill  阅读(116)  评论(0编辑  收藏  举报