C++实现页码数字统计
2017-06-26 08:32
260 查看
#include<iostream> #include<iomanip> #include<cstdlib> #include<ctime> #include<cmath> #include<vector> #include<map> #include<algorithm> #include<string> #include<sstream> using namespace std; int Str2Int(const string & s, int st, int ed) { int n = 0; for (int i = st; i < ed; ++i) { n = n * 10 + s[i]- '0'; } return n; } int pos_power(int base, int ind) { int res = 1; for (int i = 0; i < ind; ++i) res *= base; return res; } int Count2(int n) { int cnt = 0; int ord = 0; for (ord = 0; n / pos_power(10, ord) > 0; ++ord) { int bit = n / pos_power(10, ord) % 10; cnt += bit*ord* pos_power(10, ord-1); if (bit > 2) cnt += pos_power(10, ord); else if (bit == 2) cnt += n % pos_power(10, ord) + 1; } return cnt; } int main(void) { int L, R; while (cin >> L >> R) { //cout << Count2(R) << endl; //cout << Count2(R) << " " << Count2(L - 1) << endl; cout << (Count2(R) - Count2(L - 1)) << endl; } return 0; }
參考链接: <a target=_blank href="http://www.cppblog.com/AllKillMan/archive/2011/08/18/153798.html">http://www.cppblog.com/AllKillMan/archive/2011/08/18/153798.html</a>
相关文章推荐
- C++实现页码数字统计
- C++ 实现从0~100中随机生成50个数,统计出现的数字最大值和最小值,输出出现最多的次数及对应的数字
- c++通过引用实现三个数字求最大值
- C++实现字符串与数字的连接
- 统计数字问题(Java语言实现)
- 数字图像处理,小波变换一维Mallat算法的C++实现(matlab验证)
- 旋转数组的最小数字(C++ 和 Python 实现)
- 剑指offer第六题【旋转数组的最小数字】c++实现
- c++实现特殊数字矩阵
- C++实现输入一个整数,将各位数字反转后输出
- 6-7 统计某类完全平方数(20 分) 本题要求实现一个函数,判断任一给定整数N是否满足条件:它是完全平方数,又至少有两位数字相同,如144、676等。
- 计算页码,统计0到9数字出现的次数
- 【数字图像处理】C++读取、旋转和保存bmp图像文件编程实现
- 直接数字频率合成技术及其C++的实现
- 菜鸟学习c++—map使用练习 实现词频统计程序
- 统计单词个数及词频(C++实现)
- 【小程序】JAVA实现从10~50中随机生成50个数,统计出现的数字及次数,输出出现最多的次数及对应的数字,按数字升序排列。
- C++实现递归实现数字的组合
- 实现4个数字算24的C和C++
- 递归实现数字的组合(C++)