We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#include<stdio.h>#include<string.h>intmain(){chars[1000];scanf("%s",s);intdigit_counts[10]={0};// Initialize counts for each digit to 0// Iterate over each character in the stringfor(inti=0;i<strlen(s);i++){// Check if the character is a digitif(s[i]>='0'&&s[i]<='9'){// Increment the count for the corresponding digitdigit_counts[s[i]-'0']++;}}// Print the counts for each digitfor(inti=0;i<10;i++){printf("%d ",digit_counts[i]);}printf("\n");return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Digit Frequency
You are viewing a single comment's thread. Return to all comments →