其实就是两步骤,第一步判断是不是混淆数,不是直接返回false即可。第二部是判断全都是混淆数的情况下,会不会旋转后和原来一样。
题目:
结果:
代码:
bool isConfusing(int temp)
{
if(temp >= 2 && temp <= 5)
return false;
else if(temp == 7)
return false;
return true;
}
bool confusingNumber(int N){
int temp; //每一位的数字
int con = 0; //存储颠倒后的数字
int num = N;
while(num)
{
temp = num % 10;
num = num / 10;
if(temp > 1)
{
if(!isConfusing(temp))
return false;
}
if(temp == 6) temp = 9;
else if(temp == 9) temp = 6;
con = con * 10 + temp;
}
if(con == N) return false;
return true;
}