C++实现页码数字统计
来源:互联网 发布:小偶的软件 编辑:程序博客网 时间:2024/06/06 01:24
#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>
0 0
- C++实现页码数字统计
- 统计页码数字问题
- 数字统计之统计页码
- 页码数字的编程统计
- 统计页码中数字出现的次数
- 数字统计之统计页码数字出现的次数
- GridView实现数字页码分页
- 页码统计
- 计算页码,统计0到9数字出现的次数
- 湖北民族学院oj2159 之 页码的数字统计
- C语言 - 数字和字母统计之函数实现
- 数字统计二分实现
- 牛客网[编程题] 页码统计(Java实现)
- [编程题] 页码统计
- 页码统计解题报告
- 【模拟题】页码统计
- 页码统计问题
- 页码数字计算
- Median of Two Sorted Arrays
- spring中@Resource和@Autowired的区别是什么?
- 模拟器黑屏解决方法
- java之 ------ 图形界面(三)
- STL 的一些数据结构比较
- C++实现页码数字统计
- 需要学习8个重要的cmd指令
- CSS vertical-align的深入理解(二)之text-top篇
- c++ primer 学习笔记(2)迭代器
- Eclipse中自动提示的参数变成arg0,arg1的解决办法
- 关于STM32的IAP在线升级的整理
- Hadoop的简单控制台log分析
- Nim教程翻译(三)
- 多线程还是多进程的选择及区别