www.MyException.Cn  网友分享于：2013-03-30  浏览：13次

------解决方案--------------------
int f(int n)
{
int m,k,count;
if(n==1)
{printf( "%d/n ",1);return 1;}
m=n;
while(m> 0)
{
k=m%10;
if(k==1)
count++;
m=m/10;
}
count=count+f(n-1);
if(count==n)
printf( "%d/n ",n);
return count;
}

------解决方案--------------------

#include <stdio.h>
#include <conio.h>

#define LEN 20
void f(char *str) {
char a[LEN],ai=0,*fnt=str,*now,*end;

while (*++fnt);
end=fnt;
while (--fnt> =str)
if (*fnt== ' ') {
now=fnt+1;
while (now <end)a[ai++]=*now++;
a[ai++]= ' ';
end=fnt;
}
while (++fnt <end)a[ai++]=*fnt;
a[ai++]=0;
printf(a);
}

void main() {
char *str= "I am a student ";
f(str);
getch();
}

------解决方案--------------------
f(13) = 6
1、10、11、12、13
^ ^ ^^ ^ ^

---------------------------------

------解决方案--------------------
int Count1( int n )
{
//这个函数计算给定数字n中1的个数
int iRet = 0;
int m = n;
while(m> 0)
{
if( 1 == m % 10 )
++iRet;
m /= 10;
}
return iRet;
}
int Calc( int n )
{
if( n == 1 )
{
cout < < "num: " < < n < < "\tcount: " < < 1 < < "\n ";
return 1;
}
int iRet = Count1( n ) + Calc( n - 1 );
cout < < "num: " < < n < < "\tcount: " < < iRet < < "\n ";
return iRet;
}

int main()
{
Calc( 123 );
}

------解决方案--------------------
1,2,3,4,5,6,7,8,9,0和1234567890

N是任意整数不是吗?是的.

------解决方案--------------------
cy2005abc的可以得出答案，但效率是不是低了点

------解决方案--------------------

number[1000] ;

//define MAX 10000
init()
{
number[0] = 0;
number[1] = 1;
number[2] = 0;
number[3] = 0;
number[999] = 0;
}

int Get1Count(int n)
{
int nCount =0 ;
for(; n > 0 ;)
{
nCount += number[n % 1000 ]
n = n /1000;
}
return nCount;
}

------解决方案--------------------
Hylas(羽心) ( ) 信誉：100 Blog 加为好友 2007-04-23 17:53:18 得分: 0

number[1000] ;

//define MAX 10000
init()
{
number[0] = 0;