Codeforces 1157A Reachable Numbers

题目传送门

#include<iostream>
using namespace std;
int main()
{
    int n,ans=0;
    cin>>n;
    if(n<10)//n小于10,即1,2,3,4,5,6,7,8,9
    {
        cout<<9<<endl;
        return 0;
    }
    while(n>=10)
    {
        n=n+1;
        ans++;
        while(n%10==0)
        {
            n=n/10;
        }
        if(n<10)
        {
            ans+=9;
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/ytuyzh/article/details/89645893