this is in reference to the question Granama Recipies link"http://www.codechef.com/DEC12/problems/GRANAMA"

how this code will work
while(str1[j]!=’\0’)
{
count1[(str1[j]-‘a’)]++;
j++;
}

In the following code we are just maintaining the count of the characters from a to z. As for example the character ‘a’ represents the zero position in the array count1[] and when it appears in the character string str1 the zero position of count1 array is incremented by 1 (‘a’ - ‘a’ = 0). Hence we are just counting the character count in the array.

1 Like