#include
"stdio.h"
#include
"stdlib.h"
#include
"string.h"
int cnt[10] = {1};
void
count(int n)
{
while
(n)
{
cnt[n%10]++;
n = n /10;
}
}
/**
num >= 0 && num <= 9;
*/
int
count2(int src, int num)
{
char str[100] = {0};
char tmpstr[100] = {0};
sprintf(str,
"%d", src);
int len = strlen(str);
int ret = len-1;
int tmp = len - 2;
while (tmp >= 1)
{
ret *= 10;
tmp--;
}
if (!num)
{
int total = 10;
if ( len < 2)
{
total = 0;
}
tmp = 9;
for ( int k = 3; k <= len; ++k)
{
tmp *= 10;
total += tmp * (k-1);
}
if (total)
{
ret = total - 9 * ret;
}
}
int t = 0;
int t0, t1;
for (int i = 0; i < len; ++i)
{
t0 = 0;
t1 = 0;
t = 1;
for (int k = 0; k < i; ++k)
{
t0 = t0*10 + str[k]-
'0';
t *= 10;
}
t /= 10;
t0 -= t;
t0 += 1;
t = 0;
for (int k = i +1; k < len; ++k)
t1 = t1*10 + str[k]-
'0';
t1 += 1;
if (str[i]-'0'>num)
{
if (!i && !num && len > 1) t0 = 0;
t1 = 0;
}
else if (str[i]-'0'==num)
{
t0--;
}
else
{
t0--;
t1 = 0;
}
for (int k = i+1; k < len; ++k)
t0 *= 10;
ret += t0 + t1;
}
return ret;
}
int
main()
{
int
o_o = 1;
while
(o_o <= 10000)
{
memset(cnt, 0 ,
sizeof cnt);
cnt[0] = 1;
for (int i =0 ;i <= o_o; ++i)
count(i);
for ( int i = 0; i <= 9; ++i)
{
int n1 = cnt[i];
int n2 = count2(o_o, i);
if (n1- n2)
{
printf(
" o_o = %d , a[%d] = %d, %d\n",o_o, i, n1,n2 );
goto
_exit;
}
}
++o_o;
}
_exit:;
return
0;
}
posted on 2010-05-06 17:24
RUI 阅读(311)
评论(0) 编辑 收藏 引用