2015年4月20日星期一

[UVa] 1225 - Digit Counting

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int count[10]; //count the apperance of 0~9
int main(){
  int kase;
  scanf("%d",&kase);
  while(kase--){
    memset(count,0,sizeof(count));
    int input;
    scanf("%d",&input);
    //printf("INPUT=%d\n",input);
    for(int i=1;i<=input;i++){
      int tmp = i;
      while(tmp){
        int m = tmp%10;
        tmp = tmp/10;
        count[m]++;
      }
    }
    for(int i=0;i<9;i++)printf("%d ",count[i]);
    printf("%d\n",count[9]);
  }
  return 0;
}

沒有留言: