pat 1049. Counting Ones (30)
看别人的题解懂了一些些 参考《编程之美》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)的更多相关文章
- PAT 解题报告 1049. Counting Ones (30)
1049. Counting Ones (30) The task is simple: given any positive integer N, you are supposed to count ...
- pat 甲级 1049. Counting Ones (30)
1049. Counting Ones (30) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The tas ...
- PAT 甲级 1049 Counting Ones (30 分)(找规律,较难,想到了一点但没有深入考虑嫌麻烦)***
1049 Counting Ones (30 分) The task is simple: given any positive integer N, you are supposed to co ...
- PAT 1049 Counting Ones[dp][难]
1049 Counting Ones (30)(30 分) The task is simple: given any positive integer N, you are supposed to ...
- PAT 1049 Counting Ones [难]
1049 Counting Ones (30 分) The task is simple: given any positive integer N, you are supposed to coun ...
- PAT 1004 Counting Leaves (30分)
1004 Counting Leaves (30分) A family hierarchy is usually presented by a pedigree tree. Your job is t ...
- 【PAT甲级】1049 Counting Ones (30 分)(类似数位DP思想的模拟)
题意: 输入一个正整数N(N<=2^30),输出从1到N共有多少个数字包括1. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include& ...
- PAT (Advanced Level) 1049. Counting Ones (30)
数位DP.dp[i][j]表示i位,最高位为j的情况下总共有多少1. #include<iostream> #include<cstring> #include<cmat ...
- 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 ...
随机推荐
- IE浏览器中设为首页
<a onclick="this.style.behavior='url(#default#homepage)';this.setHomePage('<%=Configurati ...
- 为什么z-index不起作用
感觉很简单的东西 在用的时候 可能会遇到这样活那样的问题 这就是要注意细节:参考地址:http://www.ourjour.com/136/ 设置z-index 不起作用,可能是这三个原因: 1.父标 ...
- java_annotation_02
通过反射取得Annotation 在一上节中,我们只是简单的创建了Annotation,如果要让一个Annotation起作用,则必须结合反射机制,在Class类上存在以下几种于Annotation有 ...
- 基于GBT28181:SIP协议组件开发-----------第一篇环境搭建
原创文章,引用请保证原文完整性,尊重作者劳动,原文地址http://www.cnblogs.com/qq1269122125/p/3930018.html,qq:1269122125. SIP协议在安 ...
- uva 1378 A Funny Stone Game (博弈-SG)
题目链接:http://vjudge.net/problem/viewProblem.action?id=41555 把第i堆的每个石子看出一堆个数为n-i的石子,转换为组合游戏 #include & ...
- 安装 mysql
1.安装mysql客户端 yum install mysql 2.安装mysql 服务器端 yum install mysql-server 3.配置 mysql字符集 /etc/my.cnf 加入 ...
- 使用gdb调试(转: http://www.cnblogs.com/luchen927/archive/2012/02/07/2339003.html)
一般来说GDB主要调试的是C/C++的程序.要调试C/C++的程序,首先在编译时,我们必须要把调试信息加到可执行文件中.使用编译器(cc/gcc/g++)的 -g 参数可以做到这一点.如: > ...
- android布局1
第二类:属性值必须为id的引用名“@id/id-name” 仅RelativeLayout中有效 android:layout_below 在某元素的下方 android:la ...
- 如何根据Jquery实现两级联动
<script language="javascript" type="text/javascript" > $(function (){ ...
- Delphi-Delete 过程
过程名称 Delete 所在单元 System 过程原型 procedure Delete ( var Source : string; StartChar : Integer; Count : In ...