A.Reachable Numbers(codeforce1157/A)

Meaning of the questions: to give you an equation, enter a number.

step1: continuously adding 1 until the suffix 0;

step2: the suffix 0 lost;

Continue step1 and step2, a total number of statistics can produce different numbers.

Because we know that the implementation of the single digits when it will enter an infinite loop, so here we add 9 directly on the basis of the number of record, that each single-digit increase again.

#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
    int n,i,sum;
    while(~scanf("%d",&n))
    {
        sum=0;
        if(n%10==0)
        {
            sum++;
            n++;
        }
        for(i=n;i>=10;)
        {
            if(i%10==0)
            {
                i/=10;
            }
            else
            {
                sum++;
                i++;
            }
        }
        sum+=9;
        printf("%d\n",sum);
    }
}
View Code

 

Guess you like

Origin www.cnblogs.com/DreamingBetter/p/11621658.html