uva424 Integer Inquiry
简单的数组应用,比150!容易多了,不用什么算法
View Code
1 #include<stdio.h> 2 #include<string.h> 3 int num[200] = {0}, top = 0; 4 int main() 5 { 6 char st[102]; 7 int len, i; 8 while(gets(st) && st[0] != '0') 9 { 10 len = strlen(st); 11 if(top < len) top = len; 12 for(i = 0;i < len; i++) 13 { 14 num[i] += st[len-i-1]-'0'; 15 } 16 } 17 for(i = 0;i < top; i++) 18 { 19 num[i+1] += num[i]/10; 20 num[i] %= 10; 21 } 22 while(num[top] != 0) 23 { 24 num[top+1] += num[top]/10; 25 num[top] %= 10; 26 top++; 27 } 28 for(i = top-1;i >= 0; i--) 29 printf("%d",num[i]); 30 printf("\n"); 31 return 0; 32 }