Repeat Number

Repeat Number

时间限制: 1 Sec   内存限制: 128 MB
提交: 28   解决: 9
[ 提交][ 状态][ 论坛]

题目描述

Definition: a+b = c, if all the digits of c are same ( c is more than ten)then we call a and b are Repeat Number. My question is How many Repeat Numbers in [x,y].

输入

There are several test cases.

Each test cases contains two integers x, y(1<=x<=y<=1,000,000) described above.

Proceed to the end of file.

输出

For each test output the number of couple of Repeat Number in one line.

样例输入

1 10
10 12

样例输出

5
2
先求出所有 11 22...到1111111所有的repeat number取值,然后就好办了。
AC代码:
#include<iostream>
using namespace std;
int a[60],t;
void init(){
    int k;
    t=0; k=1;
    for(int i=0;i<5;i++){
        k=k*10+1;
        for(int j=1;j<=9;j++)
            a[t++]=k*j;
    }
    a[t++]=1111111;
}
int main(){
    init();
    int x,y;
    while(cin>>x>>y){
        int i,p,q;
        for(i=0;i<t;i++)
            if(a[i]>=2*x){
                q=i;
                break;
            }
        if(i==t){
            cout<<0<<endl;
            continue;
        }
        for(i=t-1;i>=0;i--)
            if(a[i]<=2*y){
                p=i;
                break;
            }
        if(i==-1){
            cout<<0<<endl;
            continue;
        }
        int sum=0;
        for(i=q;i<=p;i++){
            if(a[i]&1){
                if(a[i]/2-x<y-a[i]/2)
                    sum+=a[i]/2-x+1;
                else
                    sum+=y-a[i]/2;
            }
            else{
                if(a[i]/2-x<y-a[i]/2)
                    sum+=a[i]/2-x+1;
                else
                    sum+=y-a[i]/2+1;
            }
        }
        cout<<sum<<endl;
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值