#include
using namespace std;
void result(int countM,int countS)
{
if(countM > countS)
cout<<“mongooses”<<endl;
else if(countM == countS)
cout<<“tie”<<endl;
else
cout<<“snakes”<<endl;
}
int main(){
int T;
cin>>T;
for(int i=0;i<T;i++)
{
int j=0;
int countS = 0,countM=0;
char snakeMongoose[10000];
cin>>snakeMongoose;
while(snakeMongoose[j]!='\0')
{
if(snakeMongoose[j]=='s')
{
countS++;
}
if(snakeMongoose[j]=='m')
{
countM++;
if(snakeMongoose[j-1] == 's' || snakeMongoose[j+1]=='s')
{
countS--;
}
}
j++;
}
result(countM,countS);
}
return 0;
}
What’s wrong again, Do i need to validate the string ??. If not , the output is correct is again.Please suggest me, if the code has some more improvements.