CodeChef Solution Bear and Segment 01 Problem Code: SEGM01 - Solution in C | Beginner - 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

Sunday, May 7, 2017

CodeChef Solution Bear and Segment 01 Problem Code: SEGM01 - Solution in C | Beginner

CodeChef Solution Bear and Segment 01 Problem Code: SEGM01 - Solution in C | Beginner


CodeChef Online Judge Solution  Bear and Segment 01| Beginner
CodeChef Main Problem Link - https://www.codechef.com/problems/SEGM01



Problem Name: CodeChef Problem Bear and Segment 01
Problem Number : CodeChef Problem Bear and Segment 01 Solution
Online Judge : CodeChef Online Judge Solution
Level: Beginner
Problem Code : SEGM01
Solution Language : C

CodeChef Solution Bear and Segment 01 Problem Code: SEGM01 - Solution in C | Beginner

CodeChef Solution SEGM01 Code in C,CPP:

#include<string.h>
#include<stdio.h>
int main()
{
    char s[100000];
    int n,count=0,i,T,o=0,c=0;
    scanf("%d",&T);
    while(T--)
    {
        c = 0, o = 0, count=0;
        scanf("%s",&s);
        n = strlen(s);
        for(i=0; i<n-1; i++)
        {
            if((s[i]=='0'&&s[i+1]=='1')||(s[i]=='1'&&s[i+1]=='0'))
                count++;
            if(s[i]=='0')
                o++;
            if(s[i]=='1')
                c++;

        }
        if(s[n-1]=='0')
            o++;
        else
            c++;

        if((count>2)||((s[0]=='1')&&(s[n-1]=='1')&&(o!=0))||(o==n))
            printf("NO\n");
        else
            printf("YES\n");
    }
    return 0;
}

No comments:

Post a Comment