Featured Post

Variable Sized Arrays Discussions | C++ | HackerRank Variable Length Arrays in C and C++ - GeeksforGeeks

Variable Sized Arrays Variable Sized Arrays Discussions | C++ | HackerRank Consider an  -element array,  , where each index   in the array c...

Saturday, April 3, 2021

Digit Frequency Discussions | C | HackerRank HackerRank/Digit Frequency.c at master


 


Digit Frequency Discussions | C | HackerRank
HackerRank/Digit Frequency.c at master






Given a string, , consisting of alphabets and digits, find the frequency of each digit in the given string.

Input Format

The first line contains a string,  which is the given number.

Constraints


All the elements of num are made of english alphabets and digits.

Output Format

Print ten space-separated integers in a single line denoting the frequency of each digit from  to .

Sample Input 0

a11472o5t6

Sample Output 0

0 2 1 0 1 1 1 1 0 0 

Explanation 0

In the given string:

  •  occurs two times.
  •  and  occur one time each.
  • The remaining digits  and  don't occur at all.

Sample Input 1

lw4n88j12n1

Sample Output 1

0 2 1 0 1 0 0 0 2 0 

Sample Input 2

1v88886l256338ar0ekk

Sample Output 2

1 1 1 2 0 1 2 0 5 0 

#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 *s= malloc(1024*sizeof(char));
   
    int l,i,c;
    scanf("%[^\n]", s);
    
    l=strlen(s);
    for(int k=48;k<=57;k++)
    {
        c=0;
        for(i=0;i<l;i++)
        {   
            if(s[i]== (char)k)
            {
                c++;
            }
        }
        printf("%d ",c);
    
    }
    
       
    return 0;
}
    
    


















       


No comments:

Post a Comment