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 ...
随机推荐
- 关于模板中的动态取值 ---反射与javascript脚本编译
在项目中经常遇到一个问题,打印word或者打印excel的时候,我们经常使用一对一的赋值或者批量替换的方式来对模板进行修改. 但是现在遇到两种场景: 1.取值是通过自定以方法进行取值的. 如:一个销售 ...
- ArcGis(01)——地图切片以及发布底图服务
ArcGis(01)——地图切片以及发布底图服务 环境 操作系统:win10_x64 Gis版本:Arcis server 10.2 准备 1.tif格式地图资源 2.Arcis server 10. ...
- Notepad++中查找替换回车符
用Nodepad++打开文件 View->Show Symbol->Show End of Line "End of Line"行结束符,由"CR" ...
- JavaScript设计模式之命令模式
一.命令模式概念 命令模式(Command)的定义是:用来对方法调用进行参数化处理和传送,经过这样处理过的方法调用可以在任何需要的时候执行.也就是说该模式旨在将函数的调用.请求和操作封装成一个单一的对 ...
- jquery工具函数browser() 辨别浏览器
1.browser属性不是一个函数是一个全局对象,可以辨别客户端浏览器. 2.属性1:$.browser.msie如果返回true则客户端浏览器是ie.相似的$.browser.safari返回tru ...
- jquery easy ui 学习 (8)basic treegrid
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- linux内核移植 I
根据tx2440的文档, 目标也比较简单, 先编译成功, 再烧录, 根文件系统, busybox 这些. A. 准备 1. 解压tar, 修改根Makefile ARCH ?= arm CROSS_C ...
- iOS8之后CoreLocation定位的使用
在Info.plist文件中添加如下配置: //始终允许访问位置信息 (1)NSLocationAlwaysUsageDescription //使用应用程序期间允许访问位置数据 (2)NSLocat ...
- codevs 1709 钉子和小球
1709 钉子和小球 1999年NOI全国竞赛 时间限制: 2 s 空间限制: 128000 KB 题目等级 : 大师 Master 题解 查看运行结果题目描述 Description有一个三角形木板 ...
- log4j.propertise配置文件
# level : 是日志记录的优先级,分为OFF.FATAL.ERROR.WARN.INFO.DEBUG.ALL或者您定义的级别.Log4j建议只使用四个级别,优先级从高到低分别是ERROR.WAR ...