Showing posts with label The Dice Hacker Earth Problem Solution in C. Show all posts
Showing posts with label The Dice Hacker Earth Problem Solution in C. Show all posts

Saturday, 29 August 2020

The Dice Hacker Earth Problem Solution in C - good example for usage of continue in C

https://www.hackerearth.com/practice/basic-programming/implementation/basics-of-implementation/practice-problems/algorithm/the-dice-d4dc5b11/submissions/


 #include <stdio.h>

int main(){
    char str[1000000];
    scanf("%s", str);
    int c=0,i,flag=0;
    for( i=0;str[i]!='\0';i++)
    {
        if(str[i] > '6')
        {
            flag=1;
            break;
        }
        else if(str[i] == '6')
            continue;
        c++;
    }
    if(flag == 1 || str[i-1] == '6')
        printf("-1");     
    else
        printf("%d", c);
}