zoukankan      html  css  js  c++  java
  • 【PAT甲级】1049 Counting Ones (30 分)(类似数位DP思想的模拟)

    题意:

    输入一个正整数N(N<=2^30),输出从1到N共有多少个数字包括1。

    AAAAAccepted code:

     1 #define HAVE_STRUCT_TIMESPEC
     2 #include<bits/stdc++.h>
     3 using namespace std;
     4 int main(){
     5     ios::sync_with_stdio(false);
     6     cin.tie(NULL);
     7     cout.tie(NULL);
     8     int n;
     9     cin>>n;
    10     int ans=0;
    11     int l=0,r=0,low_bit=1,yushu=0;
    12     while(n/low_bit){
    13         l=n/(10*low_bit);
    14         yushu=n/low_bit%10;
    15         r=n%low_bit;
    16         if(!yushu)
    17             ans+=l*low_bit;
    18         else if(yushu==1)
    19             ans+=l*low_bit+r+1;
    20         else
    21             ans+=(l+1)*low_bit;
    22         low_bit*=10;
    23     }
    24     cout<<ans;
    25     return 0;
    26 }
    保持热爱 不懈努力 不试试看怎么知道会失败呢(划掉) 世上无难事 只要肯放弃(划掉)
  • 相关阅读:
    playbook的复用
    playbook 任务标签
    playbook handlers 触发器
    playbook循环语句
    playbook条件语句
    Ansible变量
    每日总结4.13
    每日总结4.12
    每日总结4.9
    每日总结4.8
  • 原文地址:https://www.cnblogs.com/ldudxy/p/11616744.html
Copyright © 2011-2022 走看看