Sort by

recency

|

1183 Discussions

|

  • + 0 comments

    total beginner here, dont judge but this the code that i wrote, ik it is super long but its the only one i could think of, i tried running it on vs code and it did give the required output but it didnt pass in hackerrank, can someone tell why

    include

    include

    include

    include

    int main() { char ch[30]; int count = 0; int c;

    fgets(ch, 30, stdin); // Read input
    
    // Count '0'
    count = 0;
    c = '0';
    for (int i = 0; i < strlen(ch); i++) {
        if (ch[i] == c) {
            count++;
        }
    }
    printf("%d ", count);
    
    // Count '1'
    count = 0;
    c = '1';
    for (int i = 0; i < strlen(ch); i++) {
        if (ch[i] == c) {
            count++;
        }
    }
    printf("%d ", count);
    
    // Count '2'
    count = 0;
    c = '2';
    for (int i = 0; i < strlen(ch); i++) {
        if (ch[i] == c) {
            count++;
        }
    }
    printf("%d ", count);
    
    // Count '3'
    count = 0;
    c = '3';
    for (int i = 0; i < strlen(ch); i++) {
        if (ch[i] == c) {
            count++;
        }
    }
    printf("%d ", count);
    
    // Count '4'
    count = 0;
    c = '4';
    for (int i = 0; i < strlen(ch); i++) {
        if (ch[i] == c) {
            count++;
        }
    }
    printf("%d ", count);
    
    // Count '5'
    count = 0;
    c = '5';
    for (int i = 0; i < strlen(ch); i++) {
        if (ch[i] == c) {
            count++;
        }
    }
    printf("%d ", count);
    
    // Count '6'
    count = 0;
    c = '6';
    for (int i = 0; i < strlen(ch); i++) {
        if (ch[i] == c) {
            count++;
        }
    }
    printf("%d ", count);
    
    // Count '7'
    count = 0;
    c = '7';
    for (int i = 0; i < strlen(ch); i++) {
        if (ch[i] == c) {
            count++;
        }
    }
    printf("%d ", count);
    
    // Count '8'
    count = 0;
    c = '8';
    for (int i = 0; i < strlen(ch); i++) {
        if (ch[i] == c) {
            count++;
        }
    }
    printf("%d ", count);
    
    // Count '9'
    count = 0;
    c = '9';
    for (int i = 0; i < strlen(ch); i++) {
        if (ch[i] == c) {
            count++;
        }
    }
    printf("%d ", count);
    
    return 0;
    

    }

  • + 1 comment

    include

    include

    include

    include

    int main() {

    char s[100];
    int freq[10] = {0};
    scanf("%s",s);
    for(int i = 0; s[i] != '\0'; i++){
        if(s[i] >= '0' && s[i] <= '9'){
            freq[s[i]-'0']++;
        }
    }
    for(int i = 0; i<10; i++){
        printf("%d",freq[i]);
    }
    return 0;
    

    }

  • + 0 comments

    Here is Digit Frequency Solution in c - https://programmingoneonone.com/hackerrank-digit-frequency-solution-in-c.html

  • + 0 comments

    include

    include

    include

    include

    int main() {

    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  
    char s[1000];
    int freq[10] = {0}; 
    
    scanf("%[^\n]", s); 
    for (int i = 0; i < strlen(s); i++) {
        if (s[i] >= '0' && s[i] <= '9') {
            freq[s[i] - '0']++;
        }
    }
    
    for (int i = 0; i < 10; i++) {
        printf("%d ", freq[i]);
    }  
    return 0;
    

    }

  • + 0 comments

    int main() {

    char *s;
    int i, NumberCounter[10] = {0,0,0,0,0,0,0,0,0};
    s = malloc(1024 * sizeof(char));
    scanf("%[^\n]", s);
    
    
    for (i=0;s[i]!='\0';i++)
    {            
      if (isdigit(s[i]))              
         ++NumberCounter[s[i]-'0'];                    
    }
    
    for (i=0; i<10;i++)
      printf ("%d ", NumberCounter[i]);
    

    return 0; }