求解10位数以内的水仙花数:普通的穷举算法 另:优化的深度优先搜索算法。 (三)

2014-11-24 02:44:43 · 作者: · 浏览: 11
=
你要的格式可这样输出:
printf ( "%4d-%02d-%02d %02d:%02d:%02d\n",1900+timeinfo->tm_year, 1+timeinfo->tm_mon,
timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec);

就是直接打印tm,tm_year 从1900年计算,所以要加1900,
月tm_mon,从0计算,所以要加1
其它你一目了然啦。
*/

/*
#include

函数原型是:
1.double pow(double _X,double _Y);
2.double pow(double _X,int _Y);
3.long double pow(long double _X,long double _Y);
4.long double pow(long double _X,int _Y);
5.float pow(float _X,float _Y);
6.float pow(float _X,int _Y);

原型:extern float pow(float x, float y);

用法:#include

功能:计算x的y次幂。

说明:x应大于零,返回幂指数的结果。

举例:

// pow.c

#include
#include
#include
void main()
{
printf("4^5=%f",pow(4.,5.));
getchar();
}
#include
#include

void main( void )
{
double x = 2.0, y = 3.0, z;

z = pow( x, y );
printf( "%.1f to the power of %.1f is %.1f ", x, y, z );
}


Output

2.0 to the power of 3.0 is 8.0


*/

/*
整型 [signed]int -2147483648~+2147483648
无符号整型unsigned[int] 0~4294967295
短整型 short [int] -32768~32768
无符号短整型unsigned short[int] 0~65535
长整型 Long int -2147483648~+2147483648
无符号长整型unsigned [int] 0~4294967295
字符型[signed] char -128~+127
无符号字符型 unsigned char 0~255
单精度 float 3.4 x 10^(-38)~ 3.4 x 10^(+38)
双精度double 1.7 x 10^(-308)~ 1.7 x 10^(+308)
长双精度 long double 1.7 x 10^(-308)~ 1.7 x 10^(+308)
*/

/*
time() 取得本地时间(日期时间函数)
settimeofday() 设置当前时间戳
mktime() 将时间结构数据转换成经过的秒数
localtime() 获取当地目前时间和日期
gmtime() 获取当前时间和日期
gettimeofday() 获取当前时间
ctime() 将时间日期以字符串格式表示
asctime() 将时间日期以字符串格式表示

printf("%s\n",ctime(gmtime()));

*/

/*
常见水仙花数
水仙花数又称阿姆斯特朗数。
水仙花数

水仙花数
三位的水仙花数共有4个:153,370,371,407;四位的水仙花数共有3个:1634,8208,9474;
五位的水仙花数共有3个:54748,92727,93084;
六位的水仙花数只有1个:548834;
七位的水仙花数共有4个:1741725,4210818,9800817,9926315;
八位的水仙花数共有3个:24678050,24678051,88593477
……
……
使用高精度计算,可以得到超过INT类型上限的水仙花数:
5: 93084
5: 92727
5: 54748
6: 548834
7: 9800817
7: 4210818
7: 1741725
7: 9926315
8: 24678050
8: 24678051
8: 88593477
9: 146511208
9: 912985153
9: 472335975
9: 534494836
10: 4679307774
11: 32164049650
11: 40028394225
11: 42678290603
11: 49388550606
11: 32164049651
11: 94204591914
11: 44708635679
11: 82693916578
14: 28116440335967
16: 4338281769391370
16: 4338281769391371
17: 35875699062250035
17: 21897142587612075
19: 3289582984443187032
19: 4929273885928088826
19: 4498128791164624869
20: 63105425988599693916
21: 449177399146038697307
21: 128468643043731391252
23: 27907865009977052567814
23: 35452590104031691935943
23: 27879694893054074471405
23: 21887696841122916288858
24: 174088005938065293023722
24: 188451485447897896036875
(为环保起见,24位以上的水仙花数略)
理论上,最大的水仙花数不超过34位。
*/