The SPOJ problem:Given a 40 character string representing outcomes of 40 coin tosses,  find the frequency destribution of all the possible outcome triplets.  So, for string like : HHHH....40 Hs ,the result is HHH : 38 and the  rest 0. The exact input output format is given in the link.My approach, as is clear from the code, is to iterate through the string and match all consecutive sub-strings of length 3, while increasing the frequency count.My solution got accepted, but I am not really happy with what I have done here. As you can see, there is a lot of redundant code I could not remove.For instance, if string TTT could be directly mapped to the macro TTT, somehow, and so on, a large number of lines of code could have been reduced. I know technically strings and macros are two different things, but is there some trick that I am missing?#include<stdio.h>#include<stdlib.h>#include<string.h>#include<limits.h>#define TTT 0#define TTH 1#define THT 2#define THH 3#define HTT 4#define HTH 5#define HHT 6#define HHH 7void getCount(char str[] , int count[]){    int i;    for(i=0;i<8;++i)        count[i]=0;    int l = strlen(str);    for(i=2;i<l;++i){        if(strncmp(str+i-2 , TTT , 3)==0)            ++count[TTT];        if(strncmp(str+i-2 , TTH , 3)==0)            ++count[TTH];        if(strncmp(str+i-2 , THT , 3)==0)            ++count[THT];        if(strncmp(str+i-2 , THH , 3)==0)            ++count[THH];        if(strncmp(str+i-2 , HTT , 3)==0)            ++count[HTT];        if(strncmp(str+i-2 , HTH , 3)==0)            ++count[HTH];        if(strncmp(str+i-2 , HHT , 3)==0)            ++count[HHT];        if(strncmp(str+i-2 , HHH , 3)==0)            ++count[HHH];    }}int main(){    char str[41];    int t,n,count[8],i;    scanf(%d,&t);    while(t--){        scanf(%d,&n);        printf(%d ,n);        scanf(%s,str);        getCount(str,count);        for(i=0;i<8;++i){            printf(%d ,count[i]);        }        printf(\n);    }    return 0;}
Penney Game - mapping macros to strings
c;strings;game;programming challenge;macros