【思路】:
- 只要包含3,4,7就不行
- 只要数字全为0,1,8就不行;
int rotatedDigits(int N) {
int sum=0,tmp=0;
vector<int> bad={3,4,7};
vector<int> invariant ={0,1,8};
for(int i=1;i<=N;i++){
tmp = i;
int value=0;
int part_sum=0;
int times=0;
int flags = false;
// cout<<" current: "<<i;
while(tmp>0) //查看数字组成
{
value = tmp % 10;
// cout<<" value: "<<value;
if(find(bad.begin(),bad.end(),value) != bad.end()) //有,3,4,7 错误
{
flags = true;
break;
}
if(find(invariant.begin(),invariant.end(),value) != invariant.end()) //判断是否全由0,1,8组成
part_sum++;
tmp = tmp /10;
times++;
// cout<<" part_sum: "<<part_sum<<" times: "<<times;
}
if(part_sum == times || flags == true)
sum++;
//cout<<" ||sum:"<<sum<<endl;
}
return N - sum;
}
网友评论