Question

Write in C language . Thank you

Count Sheep Jojo is having problem to sleep at night. He cant fall asleep and it makes him feel tired every day. Having this

0 0
Add a comment Improve this question Transcribed image text
Answer #1

All explanations are present in the comments ofthe code itself

CODE--

#include<stdio.h>
#include<math.h>
int main()
{
   int n,x;
   x=1;
   //take the input for n
   scanf("%d",&n);
   //run a loop for n test cases
   while(n>=x)
   {
       char ip[100000];
       //input for the string
       scanf("%s",ip);
       int b,w,i;
       i=0;
       w=0;
       b=0;
       //count the number of B's and W's in the string
       while(ip[i]!='\0')
       {
           if(ip[i]=='W')
           w++;
           else if(ip[i]=='B')
           b++;
           i++;
       }
       //loose 1 W for every 2 B's
       w=w-floor(b/2);
       //if W is still greater then 10 display the output
       if(w>=10)
           printf("Case #%d: Jojo fall asleep\n",x);
       else
           printf("Case #%d: Jojo stayed awake\n",x);
       x++;
   }
}

Output Screenshot--

5 WWWWWBBWW Case #1: Jojo stayed awake WWWWWBBBBWBWBWWWW Case #2: Jojo stayed awake WWWWWWWWWWWBBB Case #3: Jojo fall asleep

Note--

Please upvote if you like the effort.

Add a comment
Know the answer?
Add Answer to:
Write in C language . Thank you Count Sheep Jojo is having problem to sleep at...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write in C language Diamond Jojo want to propose to Lili. Jojo think he should give...

    Write in C language Diamond Jojo want to propose to Lili. Jojo think he should give Lili a diamond when he proposed to her. But Jojo is having problem to choose the diamond so he asked you to show him diamonds based on the size he told you Format Input The input consists of only one integer S, denotes the size of the diamond. Format Output Show the diamond Jojo want to see, Constraints 4 SS S 30 Page 1...

  • write in C language Decoration Lights Jojo is currently working in an office as a security....

    write in C language Decoration Lights Jojo is currently working in an office as a security. Every night, after everyone returned home, he needs to make sure all decoration lights in the office is turned off. The decoration lights are unique: each of them has a timer that will switch the light on or off every two seconds. The lights are also arranged so well that each two neighboring lights will have different state (on/off). As long as the timer...

  • C language Thank you Jojo is going to a restaurant. There are N foods listed in...

    C language Thank you Jojo is going to a restaurant. There are N foods listed in the menu, and the items are sorted increasingly based on its price. Now Jojo is wondering how many foods are there with price P. As the number of food in the menu can be a lot, Jojo will need your help to answer his questions. Jojo knows you can count really fast, so he will give you M questions. Format Input Input begins with...

  • C Programming Language Problem Title: Discount Jojo is browsing the internet while suddenly he sees an...

    C Programming Language Problem Title: Discount Jojo is browsing the internet while suddenly he sees an ad about the new cafe. The promotion is if the price of an item is N dollars, then you can buy the second item for half the price, the third item for a quarter of the original price, and so on, but if it becomes less than M dollars, then you have to pay M dollars. He wonders how much he has to pay...

  • In the language c using the isspace() function: Write a program to count the number of...

    In the language c using the isspace() function: Write a program to count the number of words, lines, and characters in its input. A word is any sequence of non-white-space characters. Have your program continue until end-of-file. Make sure that your program works for the case of several white space characters in a row. The character count should also include white space characters. Run your program using the following three sets of input:             1. You're traveling through ​               another...

  • C Programming Language Problem Title: Komodo National Park Do You know that Komodo National Park, located...

    C Programming Language Problem Title: Komodo National Park Do You know that Komodo National Park, located in Nusa Tenggara Timur (NTT), is a World Heritage Site by UNESCO, the specialized agency under United Nations (UN). One day, Lili and Bibi were on vacation on one of the islands in the Komodo National Park area and they just realized that they were living alone on that island because the cot- tage owner was completing his unfinished business on the main island....

  • Write in C language CEO's Problem Every CEO has their own unique problem, they say. The...

    Write in C language CEO's Problem Every CEO has their own unique problem, they say. The same goes to Jajo. Determining the fate of his newbom company is super tough. Every year, las board committee present him with S denoting the number of customers that use his company's services out of total M customers already in the market. And every year, C number of new customers will enter the market, and all of them will use his company's services Other...

  • //I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which...

    //I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which manipulates text from an input file using the string library. Your program will accept command line arguments for the input and output file names as well as a list of blacklisted words. There are two major features in this programming: 1. Given an input file with text and a list of words, find and replace every use of these blacklisted words with the string...

  • ‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels...

    ‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels in the string B) Count the number of consonants in the string C) Convert the string to uppercase D) Convert the string to lowercase E) Display the current string X) Exit the program The program should start with a user prompt to enter a string, and let them type it in. Then the menu would be displayed. User may enter option in small case...

  • This assignment tests your ability to write C programs that handle keyboard input, formatted console output,...

    This assignment tests your ability to write C programs that handle keyboard input, formatted console output, and input/output with text files. The program also requires that you use ctype functions to deal with the logic. In this program, you will input from the user two characters, which should both be letters where the second letter > the first letter. You will then input a file character-by-character and output those letters that fall between the two characters (inclusively) to an output...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT