## jinhao7773的专栏

http://community.csdn.net/Expert/topic/4211/4211591.xml?temp=.9405329

Consider a function which, for a given whole number n, returns the number of ones required when writing out all numbers between 0 and n.

For example, f(13)=6. Notice that f(1)=1. What is the next largest n such that f(n)=n?

#include<iostream.h>
/*

int f10(int n){
int r=1;
for(int i=1;i<=n;i++)
r=r*10;
return r;
}

int f(int n){
int r=0;
for(int i=1;i<=n;i++){
int a=1;
do{
if(i%f10(a)/f10(a-1)==1)
r++;
a++;
}while(i/f10(a-1)!=0);
}
return r;
}
*/
/*

int f(int n)
{
int ret = 0;
int ntemp=n;
int ntemp2=1;
int i=1;
while(ntemp)
{
ret += (((ntemp-1)/10)+1) * i;
if( (ntemp%10) <= 1 )
{
ret -= i;
}
if( (ntemp%10) ==1 )
{
ret += ntemp2;
}
ntemp = ntemp/10;
i*=10;
ntemp2 = n%i+1;
}
return ret;
}
*/

int f(int n){
static int r=0;
do{
if(n%10==1) r++;
n=n/10;
}while(n);
return r;
}

int main(){
for(long i=1; i<=1111111110;i++)
if(f(i)==i)
cout<<i<<endl;
cout<<"the end"<<endl;
return 0;
}

#include<iostream.h>

int main(){
for(long i=1; i<=1111111110;i++);
cout<<"the end"<<endl;
return 0;
}

08-05 1334

08-13 113

08-09 318

02-22 343

09-06 614

12-01 46

08-23 401

#### 有关c语言程序的一道题

2008年12月24日 361B 下载

03-06 14

11-08 94