CodeChef Solution Snake Procession - CodeChef SNAKPROC Solution - Online Judge Solution

Latest

It is a free Online judges problems solution list. Here you can find UVA online Judge Solution, URI Online Judge Solution, Code Marshal Online Judge Solution, Spoz Online Judge Problems Solution

Monday, June 5, 2017

CodeChef Solution Snake Procession - CodeChef SNAKPROC Solution

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("Invalid\n");
        }
        else
        {
            if(headStart)
            {
                printf("Invalid\n");
            }
            else
            {
                printf("Valid\n");
            }
        }

        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,

No comments:

Post a Comment