0 0 投票数

Description

Input

Output

Sample Input

3
2
99999999999
679898

Sample Output

case #0:
3
case #1:
101010101010
case #2:
680101

1233987显然需要把33变成34，但是后面就应该从1234000开始尝试，最小的不重复数是1234010。

int main() {
int cas;
scanf ( "%d", &cas );

for ( int t = 0; t < cas; t++ ) {
printf ( "case #%d:\n", t );
char st[1000];
scanf ( "%s", st );
solve ( st );
}

return 0;
}

void solve ( char st[] ) {

int cur = strlen ( st ) - 1;

do {
cur = isNotTarget ( st );
} while ( cur );

printf ( "%s\n", st );
}

int isNotTarget ( char st[] ) {
int ret = 0;

for ( int i = strlen ( st ) - 2; i >= 0; i-- ) {
if ( st[i] == st[i + 1] ) {
ret = i + 1;
}
}

return ret;
}

for (int i =cur+1;i<strlen(st);i++){
st[i]='0';
}

while ( st[cur] == '9' && cur > 0 ) {
st[cur] = '0';
cur--;
}

if ( st[cur] != '9' ) {
st[cur]++;

} else {

st[cur] = '0';

st[strlen ( st ) + 1] = '\0';

for ( int i = strlen ( st ); i > 0; i-- ) {
st[i] = st[i - 1];
}

st[0] = '1';

st[cur] = '0';

st[strlen ( st ) + 1] = '\0';

for ( int i = strlen ( st ); i > 0; i-- ) {
st[i] = st[i - 1];
}

st[0] = '1';

void add ( char st[], int cur ) {
for (int i =cur+1;i<strlen(st);i++){
st[i]='0';
}

while ( st[cur] == '9' && cur > 0 ) {
st[cur] = '0';
cur--;
}

if ( st[cur] != '9' ) {
st[cur]++;

} else {
st[cur] = '0';
st[strlen ( st ) + 1] = '\0';

for ( int i = strlen ( st ); i > 0; i-- ) {
st[i] = st[i - 1];
}

st[0] = '1';
}
}

2017-01-19_15-43一稿

2017-02-06_16-24二稿

2017-02-09_17-29三稿

0 0 投票数

（可选）如果您也有个人网站，不妨分享一下

0 评论