Skip to main content

An Introduction To Programming Through C++ || NPTEL Week-4 Programming Assignment 4.2


 Write a program to keep track of a match consisting of a series of games between two people: player A and player B, and report the outcome. The input consists of a sequence of letters A or B.  If the input is A, it indicates that A has won a game.  If it is B, then it indicates B has won a game.  The first player to win 5 or more games with a difference of 2 or more games between him and his opponent wins the match. If no player wins the match in 20 games then the match is declared a tie after these 20 games have been played.


INPUT


### The next n lines contain a char value each

c0

c1

...

cn

n20 . ciis the outcome of the ithgame. It can take a value of either A/B. A indicates that this game was won by Player A and B indicates that it was won by Player B. The input will end when a player has won according to the given rules or 20 characters have been given.


OUTPUT

At the end of the input, if player A wins, output “ A”, If player B wins output “B”. If no one has won, output “Tie”

Note: DO NOT output the quotes

Please print a newline( using “cout<<endl;” is one way to do it) after printing your answer





SOLUTION:


int main()

{

    int A = 0, B = 0, counter = 0;

    char C;


    while (counter < 20)

    {


        cin >> C;


        switch (C)

        {

        case 'A':

            A++;

            break;


        case 'B':

            B++;

            break;

        }

        counter++;

    }


    if (A - B > 1)

    {

        cout << "A" << endl;

    }

    else if (A == B)

    {

        cout << "Tie" << endl;

    } 

    else

    {

        cout << "B" << endl;

    }


    return 0;

}












Comments

Popular posts from this blog

The Attack Of 9/11

Once upon a time, in the early hours of a September morning in 2001, the city of New York buzzed with life, unaware that darkness was about to descend upon its skies. Four airplanes, carrying innocent passengers and dreams, embarked on routine journeys that would be forever altered by a sinister plan. High above, in the cockpit of American Airlines Flight 11, sat Mohamed Atta, a pawn in the hands of a man named Khalid Sheikh Mohammed. Little did the passengers know that this flight, and another, United Airlines Flight 175, were instruments in a plot conceived by Khalid Sheikh Mohammed, the mastermind behind the impending tragedy. At 8:46 a.m., the city's skyline was shattered as Flight 11 crashed into the North Tower of the World Trade Center. Panic gripped the streets, but before the shock could settle, another blow struck at 9:03 a.m. - Flight 175 crashed into the South Tower. The Twin Towers, symbols of prosperity, crumbled before the eyes of a horrified nation. Meanwhile, in Wa

Web Based Technologies and Multimedia Applications || NPTEL WEEK 1 ASSIGNMENT SOLUTIONS

1.) The following are different ways of sharing information through Internet   Posting to Social Network   Uploading to cloud storage such as Google Drive   Sending through a mailing list   All of the above Answer: All of the above  2.) The following is a website where entries are written as commentary or news on a particular subject such as food, politics, or local news   Blog   Twitter   Instagram   None of the above Answer: Blog 3.) FTP stands for   Food Transfer Programme   File Transfer Protocol   File Transfer Programming   Facebook To Python Answer: File Transfer Protocol 4.) The following enables access to computing resources remotely   FTP   VPN   Blog   Twitter Answer: VPN 5.) The following allows an Internet host Computer to become a terminal of another host on the Internet   TELNET   Google Groups   Microsoft OneDrive   None of the above Answer: TELNET 6.) To which protocol(s) are all hosts on the ARPANET were switched over from the older ARPANET protocols   UNIX   TCP/IP  

Can Chat GPT Predict About Stock Market

Can ChatGPT predict the stock market? To answer this question, it's crucial to understand how ChatGPT operates. Developed by OpenAI, ChatGPT is an advanced artificial intelligence language model capable of comprehending and responding to natural language input. It engages in human-like conversations with users, having been trained on extensive text data using a deep neural network. Primarily used for applications like chatbots, virtual assistants, and customer service interactions, ChatGPT's versatility allows it to understand and respond to a wide array of topics. The model employs a deep learning architecture known as a transformer model, trained on a substantial corpus of text data. This training enables the model to grasp natural language intricacies and the connections between words and phrases. When a user inputs text, ChatGPT processes it through the transformer model, generating a response based on its understanding of the input text. Techniques such as attention mechan