BPL Mubarak! - Easy Problems - Solution to Toph.co Online Judge Problem

BPL Mubarak!

By emoncse · Limits 1s, 512 MB

Bangladesh Premier League is in Sylhet for the first time. Today’s match is Sylhet Sixers vs the Dhaka Dynamites. Dhaka Dynamites seems to have a good batting line-up. There are many people coming to Sylhet International Stadium to see this match and you are one of them.
Now you want to count how many balls there are in an over. Dhaka Dynamites is batting first and Nasir Hossain from Sylhet Sixers is bowling his first over.
Nasir bowled 9 times in his first over.
This gave you an idea: Why not write a program that can determine the number of legal balls based on the outcomes of each ball and hence the number of overs played.
Given a series of outcomes of balls bowled by a bowler, you have to determine the number of legal balls and the number of overs that have been played. The following are the possible outcomes of each ball:
OutcomeDescription
NNo ball
WWide ball
DDead ball
OOut
0-6Runs scored
As always, no ball, wide ball, and dead balls are not to be counted.

Input

The input starts with an integer T (≤ 100) denoting the number of test cases. Each case starts with a line containing a string S (Length of S ≤ 100) representing the outcomes of each ball. It is guaranteed that there is at least one legal ball.

Output

For each test case print, the number of legal balls and overs played. Make sure you are using the correct pluralization (“OVER” vs “OVERS”, and “BALL” vs “BALLS”).

#include<stdio.h>
#include<string.h>
int main()
{
    int i,n,j,count;
    char s[100];
    scanf("%d",&n);
    getchar();
    for(j=0;j<n;j++)
    {
        gets(s);
        count=0;
        for(i=0;i<strlen(s);i++)
        {
            if(s[i]>='0' && s[i]<='6')
                count++;
            if(s[i]=='O')
                count++;
        }
        if(count==1)
            printf("1 BALL\n");
        if(count<6)
            printf("%d BALLS\n",count);
        if(count==6)
            printf("1 OVER\n");
        if(count>6)
        {
            if(count%6==0)
                printf("%d OVERS\n",count/6);
            else
            {
                if(count/6==1)
                {
                    if(count%6==1)
                         printf("%d OVER %d BALL\n",count/6,count%6);
                    else
                         printf("%d OVER %d BALLS\n",count/6,count%6);
                }

                     else
                         printf("%d OVERS %d BALLS\n",count/6,count%6);

            }

        }

    }
}