2 、查找最大的不重复数( 30 分)
问题描述
如果一个数字十进制表达时,不存在连续两位相同,则称之为“不重复数”。例如, 105 、 1234 和 12121 都是“不重复数”,而 11 、 100 和 1225 不是。给定一个正整数 A ,返回大于 A 的最小“不重复数”。 A 小于 100000
要求实现函数
unsigned int GetNotRepeatNum(unsigned int lValue)
【输入】 lValue : 给定的数字,返回大于该值的最小不重复数
【输出】 无
【返回】大于 iValue 的最小不重复数
示例
输入: iValue =54
返回: 56
输入: iValue =10
返回: 12
输入: iValue =98
返回: 101
输入: iValue =21099
返回: 21201
#include <cstdio>
#include <cstring>
unsigned int GetNotRepeatNum(unsigned int lValue)
{
char buf[8];
while(lValue++)
{
sprintf(buf,"%u",lValue);
int ok = 1;
for(unsigned int i=0;i<strlen(buf)-1;i++)
{
if(buf[i] == buf[i+1])
ok=0;
}
if(ok)
break;
}
return lValue;
}
int main()
{
int n;
while(1 == scanf("%u",&n))
{
printf("%u\n",GetNotRepeatNum(n));
}
return 0;
}