pat 1049. Counting Ones (30)
2013-09-03 19:08
351 查看
看别人的题解懂了一些些 参考《编程之美》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)
- PAT甲级 1049. Counting Ones (30)
- 1049. Counting Ones (30)【计算1 的个数】——PAT (Advanced Level) Practise
- PAT_A 1049. Counting Ones (30)
- PAT 1049. Counting Ones (30)
- Python实现Pat 1049. Counting Ones (30)
- PAT 1049. Counting Ones (30)(计算1到N,这些数字中1出现的个数,before i after,归纳)
- 【PAT (Advanced Level)】1049. Counting Ones (30)
- 【PAT】1049. Counting Ones (30)
- PAT (Advanced Level) Practise 1049 Counting Ones (30)
- PAT (Advanced Level) 1049. Counting Ones (30)
- PAT 1049. Counting Ones (30)
- 【PAT甲级】1049. Counting Ones (30)
- PAT 甲级 1049. Counting Ones (30)
- pat 1049. Counting Ones (30)
- PAT (Advanced Level) 1049. Counting Ones (30) 1到N中1出现的次数
- PAT 1049. Counting Ones (30)
- PAT 1049. Counting Ones (30)
- PAT 解题报告 1049. Counting Ones (30)