The Counting Problem(区间数数,很好哦!)
来源:互联网 发布:java final是实例域吗 编辑:程序博客网 时间:2024/06/08 10:45
The Counting Problem
Time Limit: 3000MS Memory Limit: 65536KTotal Submissions: 3680 Accepted: 1949
Description
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.
there are ten 0's in the list, ten 1's, seven 2's, three 3's, and etc.
Input
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.
Output
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.
Sample Input
1 1044 497346 5421199 17481496 14031004 5031714 1901317 8541976 4941001 19600 0
Sample Output
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
Source
Shanghai 2004
#include<cstdio>#include<iostream>#include<cstring>#define ll long longusing namespace std;ll b[12] = { 1, 10, 100, 1000, 10000, 100000, 1000000,10000000, 100000000, 1000000000, 10000000000, 100000000000 };ll count_num ( ll n, ll id ){ ll 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(){ ll n,m,f; ll 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; }}
0 0
- The Counting Problem(区间数数,很好哦!)
- UVa Problem 10198 Counting (数数)
- POJ 2282-The Counting Problem(组合数学_区间计数)
- pku2282 The Counting Problem
- The Counting Problem poj2282
- poj2282 The Counting Problem
- POJ2282 The Counting Problem:
- WOJ1254-The Counting Problem
- The Counting Problem UVA
- Poj 2282 The Counting Problem[统计区间 0 - 9出现的次数]
- 统计区间[a,b]各个数字出现的个数:poj 2282 The Counting Problem poj 3286
- 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
- 微博和知乎中的 feed 流是如何实现的?
- HDOJ 1026 Ignatius and the Princess I(bfs+优先队列)
- Java学习之路0722(八)(object类、异常处理)
- Winform 应用程序内嵌Webbrowser的若干问题
- 月之数
- The Counting Problem(区间数数,很好哦!)
- 1862 EXCEL排序
- PAT (Advanced Level) 1024. Palindromic Number (25) 字符串反转相加
- 算法的基础知识
- poj解题报告——1323
- uva 104 Arbitrage (DP + floyd)
- Pocket Cube
- programming-challenges The Archeologists' Dilemma (110503) 题解
- Objective-C学习笔记(三)——用Objective-C编写第一个程序:Hello,World!