給定一個整數,求出比其大的最小的不重復數字,不重復數字小于100000,不重復數字定義如下:
任意兩個相鄰位上的數字均不相等。例如:1212,323,65是不重復數字,122,100,1123為重復數字。
實例:
輸入:99
輸出:101
輸入:65
輸出:67
我編的程序如下:
#include <iostream>
using namespace std;
int main()
{
int start=99; //給出的數據,求其不重復數
int sgnl=1;
int shu=-1;
int T;
int p; 
int a[]={-1,-2,-3,-4,-5,-6};
for (int i=start;i<100000;i++)
{
// sgnl=-1;
T=i;
p=0;
while (T!=0)
{
a[p]=T%10;
T=T/10;
if (p>0)
{
if (a[p-1]==a[p])
{
sgnl=0;
break;
}
}// if (p>0)
if (T==0)
if(sgnl!=0)
{
shu=i;
i=100000;
}
p++;
}//while (T!=0)
for (int y=0;y<6;y++)
{
a[y]=0-1;
}
}// for (int i=50;i<60;i++)
cout<<shu<<endl;
return 0;
}然后我對程序做了一點修改,僅僅在for循環的里邊加了一條語句:sgnl=-1;也就是上述代碼注銷的地方,然后再次運行程序,結果無誤。
雖然發現了問題,可是我并處清楚這是問什么,所以貼出來希望各位大蝦能夠幫忙解答一下。
小弟不勝感激。
期待中。



