CF1570D

· · 题解

题目传送门 & CF 传送门

思路

这题做不了,所以只有一个人通过了。

这题只要纯模拟就行了。不难发现,这题中的 n 最终一定会变成一位数。到了一位数之后,n 就会在 1\sim 9 之间循环,不会出现别的数字了。所以,我们的标记数组只要定义 1\sim9 就够了,不需要别的题解那样用 map 标记。

代码

# include <bits/stdc++.h>
using namespace std;
int n, tot;
bool vis[15];
int main () {
    cin >> n;
    while (1) {
        ++ n, ++ tot;
        while (! (n % 10))
            n /= 10;
        if (n < 10) {
            if (vis[n]) {
                cout << tot;
                return 0;
            }
            vis[n] = 1;
        }
    }
}