CodeChef Solution Snake Procession – CodeChef SNAKPROC Solution | Beginner

Problem Name: Snake Procession Solution
Problem Code: SNAKPROC Solution in C
Problem Number : CodeChef – Snake Procession Solution, 
Online Judge : CodeChef Online Judge Solution
Category: Beginner
Solution Language : C
CodeChef Solution Snake Procession - CodeChef SNAKPROC Solution

CodeChef Solution Snake Procession – SNAKPROC Code in C:

#include <stdlib.h>
#include <stdio.h>

int
main()
{

int
testCaseNum = 0;
char
* pLineBuf = NULL;
int
bufCnt = 0, headStart = 0, errorFlg = 0;

scanf("%d", &testCaseNum);

while
(testCaseNum > 0)
{

scanf("%d", &bufCnt);

pLineBuf = (char*)malloc(bufCnt+1);
memset(pLineBuf, 0x00, bufCnt + 1);

scanf("%s", pLineBuf);
int
chkIndex = 0;

for
(chkIndex = 0; chkIndex < bufCnt; chkIndex++)
{

switch
(*(pLineBuf + chkIndex) )
{

case
'.':
break
;
case
'H':
if
(headStart)
{

errorFlg = 1;
}

else

{

headStart = 1;
}

break
;
case
'T':
if
(headStart)
{

headStart = 0;
}

else

{

errorFlg = 1;
}

break
;
default
:
break
;
}


if
(errorFlg == 1)
break
;
}


if
(errorFlg == 1)
{

printf("Invalidn");
}

else

{

if
(headStart)
{

printf("Invalidn");
}

else

{

printf("Validn");
}
}


errorFlg = 0;
headStart = 0;
bufCnt = 0;
testCaseNum--;
free(pLineBuf);
}



return
0;
}


Demonstration:

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 Snake Procession  code in C, CodeChef Snake Procession code in C++, CodeChef Snake Procession solution in C, CodeChef solution, CodeChef SNAKPROC solution in C, CodeChef SNAKPROCsolution in C++-CPP,CodeChef SNAKPROC solution in C# (C sharp),CodeChef Snake Procession solution in Java,CodeChef Snake Procession solution in Python,

By Maniruzzaman Akash

Maniruzzaman Akash is a freelance web developer with most popular Laravel PHP frameork and Vue JS

Leave a Reply

Your email address will not be published. Required fields are marked *