CodeChef Solution Snakes, Mongooses and the Ultimate Election – CodeChef SNELECT Solution

CodeChef Online Judge Solution CodeChef-Beginner Solution

CodeChef Colution Snakes, Mongooses and the Ultimate Election – CodeChef SNELECT Solution

CodeChef Online Judge Solution SNELECT | Beginner
CodeChef Problem Link – https://www.codechef.com/problems/SNELECT

Problem Name: SNELECT Solution
Problem Number : CodeChef – Snakes, Mongooses and the Ultimate Election
Online Judge : CodeChef Online Judge Solution
Category: Beginner
Solution Language : C

CodeChef Solution Snakes, Mongooses and the Ultimate Election Code in C:

#include<stdio.h>
int main()
{

char
line[100]= {0};
int
cases=0,snakes=0,mongooses=0,count=0,res=0,i=0,j=0;
scanf("%d",&cases);

for
(i=0; i<cases; i++)
{

for
( j=0; j<100; j++)
line[j]=0;
scanf("%s",&line);


j=0;
while
((line[j]=='s' || line[j]=='m') && j<99)
{

if
( (line[j]=='s' && line[j+1]=='m') || (line[j]=='m' && line[j+1]=='s') )
{

j+=2;
mongooses+=1;
}


else if
(line[j]=='m' && line[j+1]=='m' || line[j]=='m')
{

mongooses+=1;
j+=1;
}


else if
(line[j]=='s' && line[j+1]=='s' || line[j]=='s')
{

snakes+=1;
j+=1;
}

}


res=mongooses-snakes;


if
((res) > 0)
printf("mongoosesn");
else if
(res == 0)
printf("tien");
else

printf("snakesn");
snakes=mongooses=0;
}



return
0;
}


Demonstration:

After taking the simple test case and then the letter s or m and then implement the logic of snake. See the above code and I think the code is pretty clear and simple in C and you can solve the problem in any language now..
Just implement this in coding. Since having any problem just put a comment below. Thanks

Tags: CodeChef Online Judge Solution, CodeChef OJ Solution list, CodeChef Problems Solution, CodeChef solver, CodeChef all problem solution list, CodeChef area of a circle code in C, CodeChef SNELECT code in C++, CodeChef Area of a circle solution in C, CodeChef solution, CodeChef SNELECT solution in C,CodeChef SNELECT solution in C++-CPP,CodeChef SNELECT solution in C# (C sharp),CodeChef SNELECT solution in Java,CodeChef SNELECT solution in Python,

Leave a Reply

Your email address will not be published.