题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4608

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 ",len); 17 for(int i=0;i<len;i++){ 18 ans += a[i] - '0'; 19 }// printf("ans %d ",ans); 20 return ans; 21 } 22 void add(int num){ 23 int incnt = 0; 24 int temp = a[0] - '0' + num; //printf("temp %d ",temp); 25 26 if(temp > 9){ 27 incnt = 1; 28 a[0] = temp - 10 + '0'; //printf("*** %c %d ",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 "); 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]!='