Question 14 || Hacker Rank
Digit Frequency || Hacker Rank
Given a
string, , comprising of letters in order and digits, track down the recurrence
of every digit in the given string.
Input
Organization
The
principal line contains a string, which is the given number.
Limitations
Every one of
the components of num are made of english letter sets and digits.
Yield
Organization
Print ten
space-isolated numbers in a solitary line signifying the recurrence of every
digit from to .
Test
Information 0
a11472o5t6
Test
Result 0
0 2 1 0 1 1
1 1 0 0
Clarification
0
In the given
string:
happens twice.
what's more, happen one time each.
The excess
digits and don't happen by any means.
Test Info
1
lw4n88j12n1
Test
Result 1
0 2 1 0 1 0
0 0 2 0
Test Info
2
1v88886l256338ar0ekk
Test
Result 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()
{
char num[1000];
fgets(num, sizeof(num), stdin);
int frequency[10] = {0};
for (int i = 0; i < strlen(num); i++)
{
if (num[i] >= '0' && num[i] <= '9')
{
int digit = num[i] - '0';
frequency[digit]++;
}
}
for (int i = 0; i < 10; i++)
{
printf("%d ", frequency[i]);
}
return 0;
}
0 Comments