/* Program to count ocurrences of each Alphabet in a Sentence */
/* Bala Krishna */
/* www.stupidsandidiots.blogspot.com */
/* ALGORITHM TO Calculate IC value
IC = Σ (p*p) p is the frequency of eah alphabet
*/
#include <iostream>
#include <string.h>
using namespace std;
double count[26] = {0};
int fn(char *s);
int main()
{
char string[50];
cin>>string;
int l = strlen(string);
cout<<"\nString Length is: "<<l;
fn(string);
cout<<endl;
for(int j=0 ; j<26; j++)
cout<<" "<<count[j];
double IC = 0;
for(int k=0 ; k<26; k++)
{
double temp = (count[k] / l);
IC = IC + (temp * temp);
}
cout<<"\nIC value is :"<<IC;
return 0;
}
int fn(char *s)
{
//char *s;
//s = string;
int i=1;
while(*s != NULL)
{
if(*s == 'A')
count[0] =+ 1;
if(*s == 'B')
count[1] += 1;
if(*s == 'C')
count[2] += 1;
if(*s == 'D')
count[3] += 1;
if(*s == 'E')
count[4] += 1;
if(*s == 'F')
count[5] += 1;
if(*s == 'G')
count[6] += 1;
if(*s == 'H')
count[7] += 1;
if(*s == 'I')
count[8] += 1;
if(*s == 'J')
count[9] += 1;
if(*s == 'K')
count[10] += 1;
if(*s == 'L')
count[11] += 1;
if(*s == 'M')
count[12] += 1;
if(*s == 'N')
count[13] += 1;
if(*s == 'O')
count[14] += 1;
if(*s == 'P')
count[15] += 1;
if(*s == 'Q')
count[16] += 1;
if(*s == 'R')
count[17] += 1;
if(*s == 'S')
count[18] += 1;
if(*s == 'T')
count[19] += 1;
if(*s == 'U')
count[20] += 1;
if(*s == 'V')
count[21] += 1;
if(*s == 'W')
count[22] += 1;
if(*s == 'X')
count[23] += 1;
if(*s == 'Y')
count[24] += 1;
if(*s == 'Z')
count[25] += 1;
s++;
}
}
0 comments:
Post a Comment