Doubt in problem SNAKPROC snake procession

doubt
problem
snakproc

#1

Question: https://www.codechef.com/SNCKQL17/problems/SNAKPROC .This code works perfectly on my IDLE but shows wrong answer on codechef.Please let me know the changes needed:
#include<stdio.h>

int main()
{
int r;
scanf("%d",&r);
while(r–){
char a[500],b[500];
int n,i,k=0,f=0,c=0;
scanf("%d",&n);
scanf("%s",&a);
for(i=0;i<n;i++)
{
if(a*==‘H’)
{
b[k++]=a*;
}
if(a*==‘T’)
{
b[k++]=a*;
}

}
for(k=0;k<n;k++)
{
    if(b[k]=='\0')
    break;
    //printf("%c",b[k]);
    if(b[0]=='T')
    c++;
    else if(b[k]=='H' && b[k+1]=='H')
        c++;
    else if(b[k]=='H')
    f++;
    else if(b[k]=='T')
    f--;
    else if(b[n-1]=='H')
    c++;

}
//printf("%d %d",f,c);
if(c>0)
printf("invalid

");
else if(f>0)
printf("invalid
");
else
printf("valid
");
b[0]=’\0’;
}
return 0;
}


#2

Failing testcase-

1

10

H…T…T…H

there is a correction needed at line-{else if(b[n-1]==‘H’)}(that index n-1 should be changed). Also in the same for loop u should check if the value of variable “f” is either 0 or 1. If not the snake is invalid. any other value of “f” will give a invalid snake. (think why…)