看别人的题解懂了一些些    参考《编程之美》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. Asp.net 事务处理

    事务处理是在数据处理时经常遇到的问题,经常用到的方法有以下三种总结整理如下:方法1:直接写入到sql 中在存储过程中使用 BEGIN TRANS, COMMIT TRANS, ROLLBACK TRA ...

  2. struts.xml中的intercepter

    1. http://weizhilizhiwei.iteye.com/blog/1005210 Struts2 的核心——拦截器[Interceptor] 2. http://blog.csdn.ne ...

  3. 认识CSS样式

    CSS全称为“层叠样式表 (Cascading Style Sheets)”,它主要是用于定义HTML内容在浏览器内的显示样式,如文字大小.颜色.字体加粗等. 如下列代码: p{ font-size: ...

  4. 开始学习<p>标签,添加段落

    如果想在网页上显示文章,这时就需要<p>标签了,把文章的段落放到<p>标签中. 语法: <p>段落文本</p> 注意一段文字一个<p>标签, ...

  5. TCP/IP-TCP

    Don't cry over spilt milk. "覆水难收" 参考资料:TCP/IP入门经典 (第五版)  TCP/IP详解 卷一:协议 TCP是协议栈中非常重要的一个部分, ...

  6. php开发中的url地址传输加密解密函数

    function keyED($txt,$encrypt_key) //定义一个keyED { $encrypt_key = md5($encrypt_key); $ctr=0; $tmp = ''; ...

  7. jquery easy ui 学习 (6) basic validatebox

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. UVA 572 Oil Deposits油田(DFS求连通块)

    UVA 572     DFS(floodfill)  用DFS求连通块 Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format: ...

  9. (转:亲测)cnblogs博文浏览[推荐、Top、评论、关注、收藏]利器代码片段

    authour: Others(hoojo) updatetime: 2015-04-25 09:30:23 friendly link: http://www.cnblogs.com/hoojo/a ...

  10. ACCESS中类型操作(限制、转换)

    ACCESS如何保留两位小数 1.可以通过修改表结构中字段的“小数位数”即可. 2.可以通过“更新查询”,将所有该字段的值更新为round(字段名,2) ACCESS如何转换类型 每个函数都可以强制将 ...