#include<stdio.h>#include<stdlib.h>#include<math.h>int t = 0;int getLen (long long n) {//求长整形长度 int len = 1; int temp = 1; while(n/temp/10 != 0){ temp *= 10; len ++; } return len;}char * getChar (long long n) { //返回的是对应位数的数字的字符-48的字符串 int len; char *ch,*head; int i; len = getLen(n); ch = (char*)malloc(sizeof(char)*len+1); head = ch; for(i = 0; i < len; i ++){ *ch = n/(long long)pow(10,len-i-1)%10; //如果要产生对于数字的字符需要加上48 ch ++; } return head;}void fun (long long n) { if(n/10 == 0){ //个位时跳出 PRintf("%lld",n%10); exit(0); //程序提前结束,可以节约时间 } char *str,*head; int len; int i; long long s = 1; head = getChar(n); len = getLen(n);/* str = head; for(i = 0; i < len; i ++){ printf("%d",*str); str ++; }*/ str = head; for(i = 0; i < len; i ++){ if(str[i] != 0){ s *= (str[i]); } } fun(s); //递归下一位 }int main () { long long n; scanf("%d", &n); fun(n); return 0;}
新闻热点
疑难解答