Created
February 12, 2021 13:00
-
-
Save cypher-nullbyte/c76fc79a96666878efe7321f1a1214d7 to your computer and use it in GitHub Desktop.
Huffman Coding Problem | Counting no of each type of alphabets(case insensitive) in a given string.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<string.h> | |
#include<stdlib.h> | |
int main() | |
{ | |
char str[20]; | |
scanf("%[^\n]s",str); | |
int *counter= (int*)calloc(26,sizeof(int)); | |
// int counter[26]={0}; | |
int pointer=0; | |
do | |
{ | |
if(str[pointer]>=97 && str[pointer]<=122) | |
{ | |
int idx=(int)str[pointer]-97; | |
counter[idx]++; | |
} | |
else if(str[pointer]>=65 && str[pointer]<=90) | |
{ | |
int idx=(int)str[pointer]-65; | |
counter[idx]++; | |
} | |
pointer++; | |
}while(pointer<26); | |
for(int i=0;i<26;i++) | |
{ | |
if(counter[i]>0) | |
{ | |
printf("%c : %d\n",((char)(65+i)),counter[i]); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment