Saturday, 29 August 2020

One String No Trouble Hacker Earth Solution in c,Little Jhool and psychic powers Hacker Earth Solution in c

https://www.hackerearth.com/practice/basic-programming/implementation/basics-of-implementation/practice-problems/algorithm/one-string-no-trouble-37037871/submissions/

#include <stdio.h>
#include <string.h>
int main(){
    char str[1000000];
    scanf("%s", str);
    int l=strlen(str),c=1,ans=0;
    for(int i=0;i+1 < l;i++)
    {
        if(str[i] != str[i+1])
            c=c+1;
        else
        {
            if(ans < c)
                ans=c;
            c=1;
        }
    }
    if(ans < c)
        printf("%d", c);
    else    
        printf("%d",ans);
}
===============================
Little Jhool and psychic powers

https://www.hackerearth.com/practice/basic-programming/implementation/basics-of-implementation/practice-problems/algorithm/psychic-powers/submissions/


#include <stdio.h>
#include <string.h>
int main()
{
char str[1000000];
scanf("%s", str);
    int c0=0,c1=0,flag=0;
for(int i=0;str[i] != '\0';i++)
    {
        if(str[i] == '1')
        {
            c1++;
            if(c1 >= 6)
            {
                flag=1;
                break;
            }
            c0=0;
        }
        else
        {
            c0++;
            if(c0 >= 6)
            {
                flag=1;
                break;
            }
            c1=0;
        }
    }
    if(flag == 0)
        printf("Good luck!");
    else
        printf("Sorry, sorry!");
}

No comments:

Post a Comment