1 void Calculate(int a) 2 { 3 int pa = a; 4 int count = 0; 5 int b[20] = {0}; 6 7 //将pa按位存储到数组b 8 while(pa > 0) 9 { 10 b[count++] = pa%10; 11 pa = pa/10; 12 } 13 bool flag = true; //是否有重复数 14 bool carryFlag = false; //是否产生进位 15 16 //从高位开始判断是否有重复数 17 int i,j,k; 18 count--; 19 for(i=count;i>0;i--) 20 { 21 if(b[i] == b[i-1]) 22 { 23 flag = false; 24 b[i-1]++; //有可能产生进位 25 if(b[i-1]>9) 26 carryFlag = true; 27 break; 28 } 29 } 30 31 if(!flag) //如果存在重复位 32 { 33 int c = 0; 34 //将低位重复数后面的数都变成0101.... 35 for(j = i-1;j>0;j--) 36 { 37 b[j-1] = c; 38 c = (c == 0 ? 1:0); 39 } 40 41 //处理进位 42 if(carryFlag) 43 { 44 int carry = 0; 45 for(j = i-1;j<=count + 1;j++) 46 { 47 b[j] = b[j] + carry; 48 if(b[j] >= 10) 49 { 50 carry = 1; 51 b[j] = b[j] - 10; 52 } 53 } 54 } 55 pa = 0; 56 for(i = (count=1 ? count + 1:count);i >=0;i--) 57 { 58 pa = pa *10 + b[i]; 59 } 60 cout<<"the min no repeat number: "<<pa<<endl; 61 } 62 else 63 { 64 cout<<"the min no repeat number: "<<a<<endl; 65 return; 66 } 67 } 68 69 输入两个很大正数,输出它们的乘积 70 void Multiply(const char *a,const char *b) 71 { 72 assert(a!=NULL && b!=NULL); 73 int len_a = strlen(a); 74 int len_b = strlen(b); 75 int *c = new int[len_a+len_b]; 76 memset(c,0,sizeof(int) *(len_a+len_b)); 77 for(int i=0;i<len_a;i++) 78 { 79 for(int j=0;j<len_b;j++) 80 { 81 c[i+j+1] += (a[i]-'0')*(b[j]-'0'); 82 } 83 } 84 for(int i=len_a+len_b-1;i>0;i--) 85 { 86 if(c[i]>=10) 87 { 88 int carry = c[i]/10; 89 c[i-1] = c[i-1] + carry; 90 c[i] = c[i] % 10; 91 } 92 } 93 char *d = new char[len_a + len_b]; 94 int i=0; 95 while(c[i] == 0) ++i; 96 int j; 97 for(j=0;i<len_a+len_b;j++,i++) 98 { 99 d[j] = c[i] + '0'; 100 } 101 d[j] = '