/*
*给定N是一个正整数,求比N大的最小“不重复数”,这里的不重复是指没有两个相等的相邻位,如1102中的11是相
*等的两个相邻位故不是不重复数,而12301是不重复数。
*/
#include <stdio.h>
unsigned int solve(unsigned int k);
unsigned int testify(unsigned int k);
int
main(void)
{
unsigned int num;
while (1) {
scanf("%d", &num);
if (num == 0)
break;
printf("->");
solve(num);
}
/*testify*/
for ( num = 1; num < 111111; ++num) {
if (solve(num) != testify(num)) {
printf("num = %u, solve = %u, testify = %u\n", num, solve(num), testify(num));
break;
}
}
return 0;
}
int
is_num(unsigned int k)
{
if (k < 11)
return 1;
int first = k % 10;
int second;
k = k / 10;
while (k) {
second = k % 10;
if (second == first)
return 0;
first = second;
k = k / 10;
}
return 1;
}
unsigned int
solve(unsigned int k)
{
char str[100];
int start, end, mark;
if (k == 0 || k == (unsigned int)-1)
return;
++k;
if (is_num(k)) {
printf("%d\n", k);
return k;
}
sprintf(str + 1, "%d", k);
start = 1;
end = 2;
while (str[end] != '\0') {
if (str[end] == str[end -1]) {
if (str[end] == '9') {
str[end - 1] = str[end] = '0';
if (end == 2) {
start = 0;
str[0] = '1';
mark = 1;
break;
}
str[end - 2] = str[end - 2] + 1;
end -= 2;
} else {
str[end] = str[end] + 1;
mark = end +1;
break;
}
} else {
++end;
}
}
/*返回整数是为了下面的验证*/
k = 0;
for( ; start != mark; ++start) {
printf("%c", str[start]);
k = 10 * k + str[start] - '0';
}
while (str[start++] != '\0') {
printf("%c", '0');
k = 10 * k;
if (str[start++] != '\0') {
printf("%c", '1');
k = 10 * k + 1;
}
else
break;
}
printf("\n");
return k;
}
unsigned int
testify(unsigned int k){
while (!is_num(++k))
;
return k;
}