fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int n, count[10] = {0}, save = 0;
  5. scanf("%d", &n);
  6.  
  7. for(int i = 1; n != 0; i *= 10) {
  8. int digit = n % 10; //슬라이싱
  9. n /= 10; // 나머지 값으로 변경
  10.  
  11. //0은 숫자들의 이하에서 나오지만 앞에 나오는 값은 전혀 의미가 없기 때문에 이미 뺴줌
  12. count[0] -= i;
  13. for(int j = 0; j < 9; j++) count[j] += (n + (j < digit)) * i;
  14.  
  15. count[digit] += n * i + 1 + save; // 슬라싱한 자리값의 값은 (슬라이싱 * 자)
  16. save += digit * i;
  17. }
  18.  
  19. for(int i = 0; i < 10 ; i++) printf("%d ", count[i]);
  20. return 0;
  21. }
  22.  
  23. //핵심 . 각 슬라이싱 한 숫자의 밑
  24.  
Success #stdin #stdout 0s 5296KB
stdin
999
stdout
189 300 300 300 300 300 300 300 300 300