zoukankan      html  css  js  c++  java
  • 面试宝典——字符串字数统计问题

     1 #include"iostream"
     2 #include"stdio.h"
     3 using namespace std;
     4 typedef long long ll;
     5 
     6 ll f(ll n)
     7 {
     8     ll fn=0,ntemp=n;
     9     ll step;
    10     for(step=1;ntemp>0;step*=10,ntemp/=10)
    11     {
    12         fn+=(((ntemp-1)/10)+1)*step;
    13         if((ntemp%10)==1)
    14         {
    15             fn-=step-(n%step+1);
    16         }
    17     }
    18     return fn;
    19 }
    20 
    21 ll get_max_fn_equal_n(ll upper_bound)
    22 
    23 {
    24     ll n=1,fn=0;
    25     ll max=1;
    26     while(n<=upper_bound)
    27     {
    28         fn=f(n);
    29         if(fn==n)
    30         {
    31             max=n;
    32             cout<<n++<<endl;
    33         }
    34         else if(fn<n)
    35             n+=(n-fn)/10+1;
    36         else
    37             n=fn;
    38     }
    39     return max;
    40 }
    41 
    42 int main()
    43 {
    44     ll upper_bound=4000000000;
    45     cout<<f(13)<<endl;
    46     cout<<get_max_fn_equal_n(upper_bound);
    47     return 0;
    48 }
    View Code
  • 相关阅读:
    VBA开发手记
    爬虫之Scrapy框架
    RPA 介绍
    MongoDB入门
    爬虫项目汇总
    coding基本功实践
    wxpy使用
    爬虫-工具篇
    SQLAlchemy使用介绍
    wtforms组件使用实例及源码解析
  • 原文地址:https://www.cnblogs.com/acm-jing/p/10371627.html
Copyright © 2011-2022 走看看