SZU:A66 Plastic Digits

Description

There is a company that makes plastic digits which are primarily put on the front door of each house to form the house number. In order to make sure that they don’t waste any resources, they want to make the exact number of digits for the house numbers needed. You are to write a program to help the company decide how many copies of each digit it needs to make for each order it receives.

Input

The input will contains multiple test cases. The first line of the input is a single integer SZU:A66 Plastic Digits which is the number of test cases. T test cases follow.

Each test case contains two positive integers SZU:A66 Plastic Digits which indicate the range of house numbers the company has to make for a particular order. The range is inclusive of n and m.

Output

For each input test case, you are to output the number of copies of each digit that the company needs to make in the following format:

  • 0 <number of copies of digit 0>
  • 1 <number of copies of digit 1>
  • ...
  • ...
  • ...
  • 9 <number of copies of digit 9>

There should be a single space between the digit and the required copies.

There should be a single blank line between two test cases. No blank line at the end of the last test case.

Sample Input

2
1 13
1 13

Sample Output

0 1
1 6
2 2
3 2
4 1
5 1
6 1
7 1
8 1
9 1 0 1
1 6
2 2
3 2
4 1
5 1
6 1
7 1
8 1
9 1

解题思路:范围 n , m 并没有说 m>n  所以要判断范围 , if n>m   swap(n, m)

My code :

 #include <stdio.h>
#include <string.h>
int A[]; int main()
{
int t, a, b,i,j,num,tmp;
scanf("%d", &t);
while(t--){
memset(A,,sizeof(A));
scanf("%d%d",&a,&b);
if(b<a){
tmp = a;
a = b;
b = tmp;
}
int j=;
for(i=a;i<=b;++i){
num = i;
while(num>){
A[num%]++;
num/=;
}
if(num<)
A[num]++;
}
for(i=;i<;++i)
printf("%d %d\n", i,A[i]);
if(t!=)
printf("\n"); }
return ;
}
上一篇:Segment fault及LINUX core dump详解 (zz)


下一篇:Linux Core Dump【转】