zoukankan      html  css  js  c++  java
  • HDU 2498 Digits

    水题。题目这样定义的,另f(x)为x有几位,x[i]=f(x[i-1]);

    求最小的i使得x[i]==x[i-1]

    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<vector>
    #include<map>
    using namespace std;
    
    char s[1000000+10];
    int x[1000000+10];
    
    int f(int n)
    {
        int res=0;
        while(n)
        {
            n=n/10;
            res++;
        }
        return res;
    }
    
    int main()
    {
        while(~scanf("%s",s))
        {
            if(strcmp("END",s)==0) break;
            int len=strlen(s);
            x[1]=len;
            if(strlen(s)==1&&s[0]=='1') printf("1
    ");
            {
                int now=2;
                while(1)
                {
                    x[now]=f(x[now-1]);
                    if(x[now]==x[now-1])
                    {
                        printf("%d
    ",now);
                        break;
                    }
                    now++;
                }
            }
        }
        return 0;
    }
  • 相关阅读:
    map
    构造函数和对象
    for...in...and for each...in...
    事件
    JSON
    css伪类
    正则表达式
    什么是DOM、什么是BOM
    CSS颜色
    grid-layout实验
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5161098.html
Copyright © 2011-2022 走看看