回复 59楼 lin5161678
刚刚试过用位运算取位,但发现了实现的过程中数据输出会出现问题,或者这个不适合用位运算实现,刚刚就是想到说了一下,看来还是要对数据取余输出的~
[code]/*~个性签名:bug是什么意思?bug是看上去没有可能的东西实际上是有可能做到的 就是这样~2018-08-08更~*/[/code]
#include<stdio.h> #define GET_LOW( s ) \ ((s)&0x0000ffff) #define GET_HIGH( s ) \ (((s)&0xffff0000)>>16) unsigned fun( unsigned[],unsigned ); void print( const unsigned[],unsigned ); int main( void ) { unsigned a[3000]; print(a,fun(a,1001)); return 0; } unsigned fun( unsigned a[],unsigned len ) { unsigned i; unsigned j; unsigned count=3; a[1]=1; a[0]=0; a[2]=0; for (i=1;i!=len;++i) { for (j=1;j!=count;++j) a[j]=GET_LOW(a[j])*i+GET_HIGH(a[j-1]); if (GET_HIGH(a[count-1])) { a[count++]=0; } } return count; } void print( const unsigned a[],unsigned len) { while (--len) printf("%04x",GET_LOW(a[len])); puts(""); }
[此贴子已经被作者于2018-6-7 21:57编辑过]
#include <stdio.h> #include <time.h> #include <sys/time.h> char current[100] = ""; long int lTime = 0; struct tm NowTime; struct timeval st,et; #define DebugInfo(fmt,args...)\ lTime = time(NULL); \ localtime_r(&lTime, &NowTime);\ sprintf(current, "[%02d/%02d %02d:%02d:%02d]", NowTime.tm_mon+1, NowTime.tm_mday, \ NowTime.tm_hour, NowTime.tm_min, NowTime.tm_sec);\ printf("\033[33m%s %s %d -- " fmt "\033[0m\n", current, __func__, __LINE__, ##args); #define BEGIN gettimeofday(&st, NULL); #define END gettimeofday(&et, NULL); #define RESP ((et.tv_sec-st.tv_sec)*1000000 + et.tv_usec - st.tv_usec) #define SIZE 3000 int main(int argc, char** argv) { int n,i,j,k,l; sscanf(argv[1],"%d", &n); int a[SIZE]={1,0}; BEGIN for(i = 2; i <= n; i++) { //进位 for(k = 0,j = 0; j < SIZE; j++) { l = a[j]*i + k; a[j] = l%10; k = l/10; } } for(i = SIZE - 1; i >= 0; i--) if(a[i]) break; for(j=i;j>=0;j--) printf("%d",a[j]); printf("\n"); END DebugInfo("%ldus", RESP); return 0; }
[此贴子已经被作者于2018-6-5 14:54编辑过]