Sort by

recency

|

1171 Discussions

|

  • + 0 comments

    include

    include

    include

    int main() {

    char *s;int i,a[10]={0};
    s=malloc(10000);
    scanf("%[^\n]",s);
    for(i=0;i<strlen(s);i++)
    {   
        if((int) *(s+i) >47 && (int) *(s+i)<58)
        {   
            a[((int) *(s+i))-48]++;
        }
    }
    
    for(i=0;i<10;i++)
    {
        printf("%d ",a[i]);
    }
    

    }

  • + 0 comments
    #include <stdio.h>
    #include <string.h>
    
    int main() {
        char str[1000];
        int count=0;
        char num_arr[10]={'0','1','2','3','4','5','6','7','8','9'};
        scanf("%s",str);
        for(int i=0;i<10;i++){ 
            count=0;    //assigning count=0 for each digit 0-9
            for(int j=0;j<strlen(str);j++){
                if(str[j]==num_arr[i]){ //find occurences of each digit in given string 
                    count++;
                }
            }
            printf("%d ",count);
        }
        
        return 0;
    }
    
  • + 1 comment
    #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 *a = (char*)malloc(1000 * (sizeof(char)));
        fgets(a, 1000, stdin);
        int hmm[10] = {0};
        for(int i=0; i < strlen(a); i++ ){
            if (a[i] >= '0' && a[i] <= '9'){  //difference in ascii character address turns str into int
                hmm[a[i] - '0']++;
            }
        }
        for (int i = 0; i < 10; i++) {
            printf("%d ", hmm[i]);
        }
        free(a);
        return 0;
    }
    
  • + 0 comments
    #include <stdio.h>
    #include <string.h>
    
    int main() {
        char s[1000];
        scanf("%s", s);
    
        int digit_counts[10] = {0}; // Initialize counts for each digit to 0
    
        // Iterate over each character in the string
        for (int i = 0; i < strlen(s); i++) {
            // Check if the character is a digit
            if (s[i] >= '0' && s[i] <= '9') {
                // Increment the count for the corresponding digit
                digit_counts[s[i] - '0']++;
            }
        }
    
        // Print the counts for each digit
        for (int i = 0; i < 10; i++) {
            printf("%d ", digit_counts[i]);
        }
        printf("\n");
    
        return 0;
    }
    
  • + 0 comments

    My solution

    #include <stdio.h>
    #include <stdlib.h>
    
    int main() {
        char *s = (char*)malloc(1000*sizeof(char));
        int i=0,arr[10] = {0};
        
        scanf("%[^\n]",s);
        
        while(s[i] != '\0'){
            if((s[i] - '0')<=9) 
                arr[(s[i]- '0')]++;
            ++i;
        }
        
        for(i=0;i<=9;i++){
            printf("%d ", arr[i]);
        }
            
        return 0;
    }