// Given any positive integer, the result of a positive integer that is greater than this number and the smallest "no-duplicated" and "no-duplicated" is that two adjacent digits are different. // For example, 1101 is the number of duplicates, 1231 is not a complex number. Int GetMinNum (int nNum) {char Temp [20]; char OutTemp [20]; int nLen; int I, j, k; int nTemp; int nCount = 0; // first determine nNumitoa (nNum, Temp, 10); nLen = strlen (Temp); for (I = 0; I <nLen-1; I ++) {// process the number of duplicates in the input string if (Temp [I] = Temp [I + 1]) {if (I = 0) {// 998765if (Temp [I] = '9') {strcpy (OutTemp, "10"); for (j = 1; j <nLen; j ++) {OutTemp [j + 1] = (j % 2) + '0' ;}}// 889765 else {OutTemp [0] = Temp [I]; outTemp [1] = Temp [I] + 1; for (j = 2; j <nLen; j ++) {OutTemp [j] = (j % 2) + '0' ;}} else {for (k = 0; k <I; k ++) {OutTemp [k] = Temp [k];} // 10998765if (Temp [I] = '9') {OutTemp [I-1] = Temp [I-1] + 1; if (I> 2) {if (OutTemp [I-1] = OutTemp [I-2]) {Temp [I-1] + 1 ;}for (j = I; j <nLen; j ++) {OutTemp [j] = (nCount % 2) + '0'; nCount ++ ;}} // 1088765 else {OutTemp [I] = Temp [I]; OutTemp [I + 1] = Temp [I + 1] + 1; for (j = I + 2; j <nLen; j ++) {OutTemp [j] = (nCount % 2) + '0'; nCount ++ ;}} return atoi (OutTemp );}} For (I = nNum + 1; I ++) {itoa (I, Temp, 10); nLen = strlen (Temp); for (j = 0; j <nLen-1; j ++) {// repeated, jump out of the loop. If (Temp [j] = Temp [j + 1]) {break ;}}// no duplicates. I is returned. If (j = nLen-1) {return I;} return 0 ;}
If you are interested, you can split the above functions. It is really a little long, right.
int main(){int nTemp;int nRet;while(1){scanf("%d", &nTemp);if (nTemp==9999){break;}else{nRet = GetMinNum(nTemp);cout << nRet << endl;}}return 0;}