# 788.Rotated Digits

**788.Rotated Digits**

难度:Easy

> 我们称一个数 X 为好数, 如果它的每位数字逐个地被旋转 180 度后，我们仍可以得到一个有效的，且和 X 不同的数。要求每位数字都要被旋转。

如果一个数的每位数字被旋转以后仍然还是一个数字， 则这个数是有效的。0, 1, 和 8 被旋转后仍然是它们自己；2 和 5 可以互相旋转成对方；6 和 9 同理，除了这些以外其他的数字旋转以后都不再是有效的数字。

现在我们有一个正整数 N, 计算从 1 到 N 中有多少个数 X 是好数？

```
示例:
输入: 10
输出: 4
解释: 
在[1, 10]中有四个好数： 2, 5, 6, 9。
注意 1 和 10 不是好数, 因为他们在旋转之后不变。
注意:

N 的取值范围是 [1, 10000]。
```

按题意判断即可。

```
class Solution {
private:
    bool isvalid(int N)
    {
        string ns=to_string(N);
        string res;
        for(auto i:ns)
        {
            if(i=='2')
                res+='5';
            else if(i=='5')
                res +='2';
            else if(i=='6')
                res +='9';
            else if(i=='9')
                res +='6';
            else if(i=='0' || i=='1' || i=='8')
                res+=i;
            else 
                return false;
            
        }
     //   cout <<ns << "+" <<res<<endl;
        return res!=ns;
    }
public:
    int rotatedDigits(int N) {
        int res=0;
        for(int i=1;i<=N;i++)
            res +=isvalid(i);
        return res;
    }
};
```

> 执行用时 : 40 ms, 在Rotated Digits的C++提交中击败了34.66% 的用户\
> 内存消耗 : 8.4 MB, 在Rotated Digits的C++提交中击败了64.06% 的用户


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dfine.gitbook.io/leetcode/788.rotated_digits.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
