WOJ1254-The Counting Problem
来源:互联网 发布:炉石传说淘宝充值 编辑:程序博客网 时间:2024/06/05 15:33
Given two integers a and b, we write the numbers between a and b, inclusive, in a list. Your task is to calculate the number of occurrences of each digit. For example, if a = 1024 and b = 1032, the list will be
1024 1025 1026 1027 1028 1029 1030 1031 1032
there are ten 0's in the list, ten 1's, seven 2's, three 3's, and etc.
输入格式
The input consists of up to 500 lines. Each line contains two numbers a and b where 0 < a, b < 100000000. The input is terminated by a line `0 0', which is not considered as part of the input.
输出格式
For each pair of input, output a line containing ten numbers separated by single spaces. The first number is the number of occurrences of the digit 0, the second is the number of occurrences of the digit 1, etc.
样例输入
1 1044 497346 5421199 17481496 14031004 5031714 1901317 8541976 4941001 19600 0
样例输出
1 2 1 1 1 1 1 1 1 185 185 185 185 190 96 96 96 95 9340 40 40 93 136 82 40 40 40 40115 666 215 215 214 205 205 154 105 10616 113 19 20 114 20 20 19 19 16107 105 100 101 101 197 200 200 200 200413 1133 503 503 503 502 502 417 402 412196 512 186 104 87 93 97 97 142 196398 1375 398 398 405 499 499 495 488 471294 1256 296 296 296 296 287 286 286 247
#include<cstdio>#include<iostream>using namespace std;long long b[12] = { 1, 10, 100, 1000, 10000, 100000, 1000000,10000000, 100000000, 1000000000, 10000000000, 100000000000 };long long count_num (long long n,long long id ) {long long left, m, sum = 0;for ( int i = 1; i < 12; i++ ) {left = n / b[i] - (id==0);sum += left * b[i-1];m = (n % b[i] - n % b[i-1]) / b[i-1]; //求出从第到高的第i位上的具体数字if ( m > id ) sum += b[i-1];else if ( m == id ) sum += n % b[i-1] + 1;if ( n < b[i] ) break;}return sum;}int main() {long long n,m,f,a[10];int i;while(cin>>n>>m&&(m+n)) {if(n>m) {f=n;n=m;m=f;}for(i=0; i<=9; i++) {a[i]=count_num(m,i)-count_num(n-1,i);}for(i=0; i<9; i++) {cout<<a[i]<<" ";}cout<<a[9]<<endl;}}
- WOJ1254-The Counting Problem
- pku2282 The Counting Problem
- The Counting Problem poj2282
- poj2282 The Counting Problem
- POJ2282 The Counting Problem:
- The Counting Problem UVA
- pku 2282 The Counting Problem
- poj 2282 The Counting Problem
- POJ-2282-The Counting Problem
- [POJ] 2282 -> The Counting Problem
- POJ 2282 The Counting Problem
- UVa 1640 The Counting Problem
- POJ 2282 The Counting Problem
- POJ2282:The Counting Problem(数位DP)
- POJ 2282 The Counting Problem,组合数学
- The Counting Problem - POJ 2282 数位dp
- poj2282 The Counting Problem 数位dp
- HDOJ 1663 The Counting Problem 打表
- springview
- 致己
- Qt 之 QSqlRelationalDelegate Class
- android Context 详解
- Attempt to invoke virtual method 'int java.lang.Object.hashCode()' on a null object reference(Fb)
- WOJ1254-The Counting Problem
- 利用brupsuite或python 破解登录账号与密码
- 数据模型
- 【PAT】【Advanced Level】1107. Social Clusters (30)
- 云计算到底是什么?
- ebay抓取specific 考虑remove 0results
- 转换器(Converter)模式
- redis入门
- idea开发web项目打包上传到服务器