Computer Programming Contest Preparation

ToolBox - Source for: 12/1225/Main.java



/home/toolbox/public_html/solutions/12/1225/Main.java
    1 import java.io.*;
    2 import java.util.Scanner;
    3 
    4 
    5 class Main
    6 {
    7 
    8     static int[] count = new int[10];
    9 
   10     static void init()
   11     {
   12         count[0] = 0;
   13         count[1] = 0;
   14         count[2] = 0;
   15         count[3] = 0;
   16         count[4] = 0;
   17         count[5] = 0;
   18         count[6] = 0;
   19         count[7] = 0;
   20         count[8] = 0;
   21         count[9] = 0;
   22 
   23     }
   24 
   25     static void process(int num)
   26     {
   27 
   28         for(int i=1; i<=num; i++)
   29             {
   30                 int tmp = i;
   31                 while (0 < tmp)
   32                     {
   33                         count[tmp % 10] += 1;
   34                         tmp = tmp / 10;
   35                     }
   36             }
   37 
   38     }
   39 
   40     static void output()
   41     {
   42 
   43         for(int i=0; i < 9; i++)
   44             {
   45                 System.out.printf("%d ", count[i]);
   46             }
   47         System.out.println(count[9]);
   48 
   49     }
   50 
   51     public static void main(String[] args)
   52     {
   53         Main myWork = new Main();
   54         Scanner scan = new Scanner(System.in);
   55         int cases = scan.nextInt();
   56         for(int i = 0; i < cases; i++)
   57             {
   58                 myWork.init();
   59                 myWork.process(scan.nextInt());
   60                 myWork.output();
   61             }
   62     }
   63 }
   64