PAT Advanced Level 1049
来源:互联网 发布:新手学编程怎么开始 编辑:程序博客网 时间:2024/05/22 05:52
题目地址:http://pat.zju.edu.cn/contests/pat-a-practise/1049
思路分析:对数的每一位进行分析。每一位出现1的个数由高位数字、低位数字和本位数共同决定
代码如下:
#include<stdio.h>int CountOnes(int n){int count=0;int factor=1;int higher,lower,cur;while(n/factor!= 0){higher=n/(factor*10);lower=n-(n/factor)*factor;cur=(n/factor)%10;switch(cur){case 0:count+=higher*factor;break;case 1:count+=higher*factor+lower+1;break;default:count+=higher*factor+factor;}factor=factor*10;}return count;}int main(){int n;scanf("%d",&n);printf("%d\n",CountOnes(n));return 0;}
0 0
- PAT Advanced Level 1049
- Pat(Advanced Level)Practice--1049(Counting Ones)
- PAT Advanced Level 1077
- PAT Advanced Level 1078
- PAT Advanced Level 1079
- PAT Advanced Level 1080
- PAT Advanced Level 1010
- PAT Advanced Level 1016
- PAT Advanced Level 1018
- PAT Advanced Level 1039
- PAT Advanced Level 1060
- PAT Advanced Level 1026
- PAT Advanced Level 1029
- PAT Advanced Level 1030
- PAT Advanced Level 1033
- PAT Advanced Level 1034
- PAT Advanced Level 1038
- PAT Advanced Level 1045
- HB 6465
- Android工作原理详解
- memcache
- 块变更跟踪(Block change tracking)
- 安卓系统4.4原理概论
- PAT Advanced Level 1049
- redis
- 用户和组的管理
- 将u-boot2014.04移植到mini2440上的一些想法
- 中国制造世界杯就差个国足 随处可见中国元素
- VB.net 学习总结
- How to pause the game in Uniy3D
- 线程间的参数传递
- Android+3D游戏开发技术详解与典型案例