看别人的题解懂了一些些    参考《编程之美》P132 页《1 的数目》

#include<iostream>
#include<stdio.h>
using namespace std;
int getone(int n)
{
int ans=0,base=1,right,left,now;
while(n/base)
{
right=n%base;
left=n/(base*10);
now=(n/base)%10;
if(now==0)ans+=left*base;
else
if(now==1)ans+=left*base+right+1;
else
ans+=(left+1)*base;
base*=10;
}
return ans;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
printf("%d\n",getone(n));
}
return 0;
}

pat 1049. Counting Ones (30)的更多相关文章

  1. PAT 解题报告 1049. Counting Ones (30)

    1049. Counting Ones (30) The task is simple: given any positive integer N, you are supposed to count ...

  2. pat 甲级 1049. Counting Ones (30)

    1049. Counting Ones (30) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The tas ...

  3. PAT 甲级 1049 Counting Ones (30 分)(找规律,较难,想到了一点但没有深入考虑嫌麻烦)***

    1049 Counting Ones (30 分)   The task is simple: given any positive integer N, you are supposed to co ...

  4. PAT 1049 Counting Ones[dp][难]

    1049 Counting Ones (30)(30 分) The task is simple: given any positive integer N, you are supposed to ...

  5. PAT 1049 Counting Ones [难]

    1049 Counting Ones (30 分) The task is simple: given any positive integer N, you are supposed to coun ...

  6. PAT 1004 Counting Leaves (30分)

    1004 Counting Leaves (30分) A family hierarchy is usually presented by a pedigree tree. Your job is t ...

  7. 【PAT甲级】1049 Counting Ones (30 分)(类似数位DP思想的模拟)

    题意: 输入一个正整数N(N<=2^30),输出从1到N共有多少个数字包括1. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include& ...

  8. PAT (Advanced Level) 1049. Counting Ones (30)

    数位DP.dp[i][j]表示i位,最高位为j的情况下总共有多少1. #include<iostream> #include<cstring> #include<cmat ...

  9. PAT Advanced 1049 Counting Ones (30) [数学问题-简单数学问题]

    题目 The task is simple: given any positive integer N, you are supposed to count the total number of 1 ...

随机推荐

  1. NSString截取字符串

     NSString 是经常会用到的,很多时候需要对字符串进行一些处理,本文简单介绍字符串截取操作: 比如: 1.定义一个字符串a, 截取a的某一个部分(子串) NSString *a = @" ...

  2. angularJS学习手册(1)

    欢迎来到augularJS的学习 一.什么是angularJS? angular的英文意思是角,为什么要叫angular我也不知道. AngularJS是一个MV*(Model-View-Whatev ...

  3. [LeetCode OJ] Reorder List—Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…

    For example,Given {1,2,3,4}, reorder it to {1,4,2,3}. /** * Definition for singly-linked list. * str ...

  4. GitHub-修改以下host-ip可加快访问速度

    #GitHub START 207.97.227.239    github.com 204.232.175.94    gist.github.com 107.21.116.220    help. ...

  5. N3292x IBR介绍

    N3292x IBR介绍 1 IBR启动流程 图1-1 IBR启动流程 CHIP_CFG[0] Mode 0 Boot from IBR Recovery Mode with crystal inpu ...

  6. 激活office 2013

    1.下载office 2013激活工具:microsoft toolkit 2.解压文件,运行Microsoft Toolkit.exe,选择office,即箭头标识处

  7. jquery mobile selectmenu下拉菜单

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...

  8. ORACLE数据库多表关联查询效率问题解决方案

    最近在做项目中遇到多表关联查询排序的效率问题(5张以上40W+数据的表),查询一次大概要20多秒,经过一番苦思冥想,处理方案如下: 1.软件设计初期,需要一对一关联的表应该设计在一张大表里,这样虽然字 ...

  9. centos 6.5 服务器安装 (LNMP ntfs文件支持 PHP-RPM CHROOT沙盒)

    centos 6.5 最小化安装 进入系统 手动开启网卡 #ifconfig eth0        //(默认会自动获得ip) 修改网站配置文件,默认开启 #cd /etc/sysconfig/ne ...

  10. 平稳退化,JS和HTML标记分离,极致性能的JavaScript图片库

    index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...