hdu 4608 I-number 大整数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4608
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <cstdio> 2 #include <cmath> 3 #include <algorithm> 4 #include <iostream> 5 #include <cstring> 6 #include <queue> 7 #include <vector> 8 #define maxn 105000 9 using namespace std; 10 11 int len; 12 char a[maxn],b[maxn]; 13 14 15 int getsum(){ 16 int ans = 0; //printf("%d\n",len); 17 for(int i=0;i<len;i++){ 18 ans += a[i] - '0'; 19 }// printf("ans %d\n",ans); 20 return ans; 21 } 22 void add(int num){ 23 int incnt = 0; 24 int temp = a[0] - '0' + num; //printf("temp %d\n",temp); 25 26 if(temp > 9){ 27 incnt = 1; 28 a[0] = temp - 10 + '0'; //printf("*** %c %d\n",a[0],temp); 29 } 30 else a[0] = temp + '0'; 31 int cnt = 1; 32 while(incnt && cnt < len){ 33 temp = a[cnt] - '0' + incnt; 34 if(temp>9){ 35 incnt = 1; 36 a[cnt] = temp - 10 + '0'; 37 } 38 else {incnt = 0; a[cnt] = temp + '0';} 39 cnt++; 40 } 41 if(incnt && cnt == len){ 42 a[cnt] = '1'; 43 len ++; 44 } 45 } 46 47 int main() 48 { 49 //if(freopen("input.txt","r",stdin)== NULL) {printf("Error\n"); exit(0);} 50 51 int T; 52 cin>>T; 53 while(T--){ 54 55 int numzero = 0; 56 scanf("%s",b); 57 58 while(b[numzero] == '0'){ 59 numzero++; 60 } 61 62 int cnt = numzero; 63 len = 0; 64 for(int i=0;b[cnt]!='\0';i++) {a[i] = b[cnt++]; len++; } 65 66 for(int i=0;i<len/2;i++){ 67 int temp = a[i]; 68 a[i] = a[len-1-i]; 69 a[len-1-i] = temp; 70 } 71 int sum = getsum()%10; //printf("%d %d\n",len,sum); 72 if(sum == 0) sum = 9; 73 int time = 0; 74 while(sum != 0 && time < 20){ 75 add(1); //printf("%d %d\n",len,sum); 76 sum = getsum()%10; 77 time++; 78 } 79 while(numzero--) printf("0"); 80 for(int i=len-1;i>=0;i--) printf("%c",a[i]); 81 printf("\n"); 82 } 83 }