Problem K. JiLi Number
Description
Driver Ji likes the digit “1”. He has an accumulator which shows the sum of input number. He lists all of positive number no more than N and starts counting from one, two, three…Every time he counts a number he will add the number of digit “1” in this number to accumulator at the same time. The amazing thing happens! At some times, when he finishes counting a number X, the number which on the accumulator is X exactly, he will regard X as “JiLi Number” which means lucky number. Now he wants to know the number of “JiLi Numbers” and the biggest “JiLi Number” no more than N.
Input
There are several test cases and the each test case is a line contains an positive integer N.(1
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <map>
using namespace std;
int strcmpx(char *s1,char *s2)
{
int len1 = strlen(s1);
int len2 = strlen(s2);
if(len1 < len2) return -1;
else if(len1 > len2) return 1;
else
{
bool flag = true;
for(int i = 0; i < len1; i++)
{
if(s1[i] < s2[i]) return -1;
else if(s1[i] > s2[i]) return 1;
}
return 0;
}
}
long long mp[100] = {1,199981,199982,
199983,
199984,
199985,
199986,
199987,
199988,
199989,
199990,
200000,
200001,
1599981,
1599982,
1599983,
1599984,
1599985,
1599986,
1599987,
1599988,
1599989,
1599990,
2600000,
2600001,
13199998,
35000000,
35000001,
35199981,
35199982,
35199983,
35199984,
35199985,
35199986,
35199987,
35199988,
35199989,
35199990,
35200000,
35200001,
117463825,
500000000,
500000001,
500199981,
500199982,
500199983,
500199984,
500199985,
500199986,
500199987,
500199988,
500199989,
500199990,
500200000,
500200001,
501599981,
501599982,
501599983,
501599984,
501599985,
501599986,
501599987,
501599988,
501599989,
501599990,
502600000,
502600001,
513199998,
535000000,
535000001,
535199981,
535199982,
535199983,
535199984,
535199985,
535199986,
535199987,
535199988,
535199989,
535199990,
535200000,
535200001,
1111111110};
int main()
{
char s[1000];
long long ten[15];
ten[0] = 1;
for(int i = 1; i <= 13; i++)
{
ten[i] = ten[i - 1]*10;
}
while(~scanf("%s",s))
{
char ch[1000];
ch[0] = 1;
for(int i = 1; i <= 11; i++) ch[i] = '0';
ch[12] = '/0';
if(strcmpx(s,ch) < 0)
{
int len = strlen(s);
long long ans = 0;
int p = 0;
for(int i = len - 1; i >= 0; i--)
{
ans += (s[i] - '0')*ten[p++];
}
//cout<<"ans == "<<ans<<endl;
int sum = 0;
long long term;
bool flag = false;
for(int i = 0; i <= 82; i++)
{
if(ans > mp[i])
{
sum++;
}
else if(ans == mp[i])
{
sum++;
term = mp[i];
flag = true;
break;
}
else
{
term = mp[i - 1];
flag = true;
break;
}
}
if(flag) printf("%d %lld\n",sum,term);
else printf("83 1111111110\n");
}
else{
//cout<<"a"<<endl;
printf("83 1111111110\n");
}
}
return 0;
}