Help Schumacher!

Good News… Schumi’s Comin’ back to Formula One!!! As we all know, Michael Schumacher will be making his grand comeback on 23rd August. Now, Schumi needs to strategize his next race in Valencia, Spain. And guess what… Schumi will need your help!!!

Schumacher will be doing some test runs on the Valencia Track, and he needs to know how many times he applies the brake in the lap. Assume that the car’s speed keeps on decreasing till the brake is released. This will help Schumi recognize his weak spots. From these results, his managers can decide the number of pit stops, type of tyres, and all other stats that will help him win the Valencia Race. So help Schumi attain a pole position in the Qualifiers!

Input

The first line of input will be ‘n’ – the number of test runs that Schumacher does. Then the next ‘n’ lines will contain ‘m’ – the number of times he checks his speed during the lap. The next line will contain ‘m’ numbers, which are the speeds measured. Here, 1<=n<=100 and 3<=m<=100.

 

Output

The Output should determine the number of times he applies the brake in the lap.

 

Input.txt

3

5

0 23 89 145 121

10

89 75 100 56 46 36 40 80 150 80

8

89 88 89 90 89 90 87 86

 

Output

1

3

3

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.IO;

using System.Text.RegularExpressions;

 

namespace NumberOfBrakes

{

    class Program

    {

        static void Main(string[] args)

        {

            try

            {

                StreamReader sr = new StreamReader(@"C:\input.txt");

                int numberOfTestRuns = int.Parse(sr.ReadLine());

                for (int run = 0; run < numberOfTestRuns; run++)

                {

                    int[] speed = new int[int.Parse(sr.ReadLine())];

                    string str = sr.ReadLine();

                    Console.WriteLine(str);

                    Regex reg = new Regex(" ");

                    int count = -1;

                    foreach (string val in reg.Split(str))

                    {

                        speed[++count] = int.Parse(val);

                    }

                    int numberOfBrakes = 0, flag = 0;

                    for (int i = 0; i < speed.Length – 1; i++)

                    {

                        if (speed[i + 1] < speed[i] && flag == 0)

                        {

                            numberOfBrakes++;

                            flag = 1;

                        }

                        else if (speed[i + 1] > speed[i])

                        {

                            flag = 0;

                        }

                    }

                    Console.WriteLine("Number of times brakes applied = " + numberOfBrakes.ToString());

                }

                sr.Close();

            }

            catch (Exception e)

            {

                Console.WriteLine(e.Message);

            }

        }

    }

}

Output
==================================
0 23 89 145 121
Number of times brakes applied = 1
89 75 100 56 46 36 40 80 150 80
Number of times brakes applied = 3
89 88 89 90 89 90 87 86
Number of times brakes applied = 3
Press any key to continue . . .

Advertisements
This entry was posted in Information Technology. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s