Skip to content

Instantly share code, notes, and snippets.

@cypher-nullbyte
Created February 12, 2021 13:00
Show Gist options
  • Save cypher-nullbyte/c76fc79a96666878efe7321f1a1214d7 to your computer and use it in GitHub Desktop.
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.
#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