Sort by

recency

|

1188 Discussions

|

  • + 0 comments

    int main() {

    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 
    char str[1000];
    int count[10] = {0};
    
    fgets(str, sizeof(str), stdin);
    str[strcspn(str, "\n")] ='\0';
    
    for(int i=0; i<strlen(str); i++){
        if(str[i] >= '0' && str[i]<= '9'){
            int digit = str[i] - '0';
            count[digit]++;
        }  
    }
    for (int k=0; k<10; k++){
        printf("%d ", count[k]);
    }
    return 0;
    

    }

  • + 0 comments
    using the ASCII value concept
    
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    
    int main() {
    
        char* arr;
        arr = (char*)malloc(sizeof(char)*1001);
        int total = 0;
        scanf("%s",arr);
        arr = (char*)realloc(arr,sizeof(char)*(strlen(arr)+1));
        int* countno;
        countno = (int*)calloc(sizeof(int),10);
        for(int i = 0;i < strlen(arr);i++){
            ((int)arr[i] >47 && (int)arr[i] <58)?countno[(int)arr[i] - 48] += 1 :(countno[0] = countno[0]); 
        }   
        free(arr);
        arr = NULL;
        
        for(int i =0; i<10;i++){
            printf("%d ",countno[i]);
        }
        
        free(countno);
        countno = NULL;
        
        return 0;
    }
    
  • + 0 comments

    **Mine Solution **

    #include<ctype.h>
    
    
    char S[1000];
    int a[] = {0,0,0,0,0,0,0,0,0,0};
    scanf("%s",&S);
    for(int i=0; i<strlen(S); i++){ if(isdigit(S[i])){ a[S[i]-'0'] += 1; } }
    for(int i=0; i<10; i++){ printf("%d ",a[i]); }
    
  • + 0 comments

    This is a great beginner-friendly string manipulation and counting problem! Cricketbuzz com ID

  • + 0 comments

    This is a great problem for practicing string manipulation and frequency counting in programming! cricketbuzz.com login mahadev