• + 0 comments
    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    #include <stdlib.h>
    
    int main() {
    
        /* Enter your code here. Read input from STDIN. Print output to STDOUT */
        char *str = (char*) malloc(1024);
        int nums[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
        
        if(str == NULL) {
            printf("Memory allocation failed\n");
            return 1;
        }
        
        scanf("%s", str);
    
        for(int i; str[i] != '\0'; i++)
        {
            if (str[i] >= '0' && str[i] <= '9')
            {
                int num = str[i] - '0';  // Convert char to int
                nums[num]++;
            }
        }
        
        for (int i=0; i<10; i++)
        {
            printf("%d ", nums[i]);
        }
        
        free(str);
        return 0;
    }