Digit frequency solution in c hackerrank solution

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

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 
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4. int main()
  5. {
  6. int i,f,j;
  7. char s[1000];
  8. scanf("%[^\n]s",s);
  9. for(j='0';j<='9';j++)
  10. {
  11. f=0;
  12. for(i=0;i<strlen(s);i++)
  13. {
  14. if(s[i]==j)
  15. f++;
  16. }
  17. printf("%d ",f);
  18. }
  19. return 0;
  20. }

Comments

Popular posts from this blog

Create account in java |deposit money|withdraw money

Library Management System in python OOPs Concept