Orthographic Projection

Your program is required to output the view of a map as seen from the south direction.

INPUT

The input will consist of several lines containing the details of each building. Each building will be defined by the coordinates of its North West corner, width (along west-east), length (along north-south) and height (perpendicular to the plane) in the form of integers in a single line, separated by one or many spaces. The first two integers will determine the position of North West corner; the next integers will define the width, length and height. The number of buildings can be assumed to be less than 100. The height and width can be assumed to be less than 200. The input is terminated by a line containing five zeroes separated by one or more spaces.

 

OUTPUT

The buildings are numbered according to the input. The first building in the input corresponds to #1 and similarly other buildings follow. The first line will print “OUTPUT IS” in uppercase letters. The next line should tell the number of buildings visible to the person standing to the south of the map. The following line should tell the sequence of buildings as seen to the person from west to east, separated by one or multiple spaces. This means that if buildings #1 and #2 are the visible buildings and the North West corner of building #2 is west of building #1, then 2 is printed before 1. If two buildings have the same width and same x coordinate of the North West corner. The building most south will be printed first. For example if building #3 and #4 are such buildings and #3 is south of building #4, the number 3 will be printed before 4.

 

 

SAMPLE INPUT:

0 160 55 70 40

90 155 150 30 29

215 110 30 105 32

10 80 50 20 50

75 110 85 60 30

0 50 60 50 42

75 20 40 15 90

155 40 45 30 55

0 0 0 0 0

 

SAMPLE OUTPUT:

OUTPUT IS

7

6 4 7 5 8 2 3

 

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            StreamReader sr = new StreamReader(@"D:\input.txt");
            ArrayList al = new ArrayList();
            string str = sr.ReadLine();
            while (str != null)
            {
                al.Add((string)str);
                str = sr.ReadLine();
            }
            sr.Close();
            Console.WriteLine("Number of buildings: " + al.Count);
            //Detemining number of rows and columns of the two dimensional matrix
            int row = 0, col = 0;
            for (int i = 0; i < al.Count; i++)
            {
                str = (string) al[i];
                Regex reg = new Regex(" ");
                string[] tempStrArray = reg.Split(str);
                if (int.Parse(tempStrArray[0]) + int.Parse(tempStrArray[2]) > row)
                {
                    row = int.Parse(tempStrArray[0]) + int.Parse(tempStrArray[2]);
                }
                if (int.Parse(tempStrArray[1]) > col)
                {
                    col = int.Parse(tempStrArray[1]);
                }
            }
            Console.WriteLine("Number of rows: " + row);
            Console.WriteLine("Number of columns: " + col);
            string[,] buildingMatrix = new string[(row + 1), (col + 1)];
            //Initializing building matrix
            for (int i = 0; i < al.Count; i++)
            {
                str = (string)al[i];
                Regex reg = new Regex(" ");
                string[] tempStrArray = reg.Split(str);
                for (int j = int.Parse(tempStrArray[0]); j <= (int.Parse(tempStrArray[0]) + int.Parse(tempStrArray[2])); j++)
                {
                    for (int k = (int.Parse(tempStrArray[1]) – int.Parse(tempStrArray[3])); k <= int.Parse(tempStrArray[1]); k++)
                    {
                        buildingMatrix[j, k] = (i + 1).ToString() + " " + tempStrArray[4];
                    }
                }
            }
            List<string> buildingList = new List<string>();
            for (int i = 0; i < buildingMatrix.GetLength(0); i++)
            {
                int currentMaxHeight = 0;
                for (int j = 0; j < buildingMatrix.GetLength(1); j++)
                {
                    if (buildingMatrix[i, j] != null)
                    {
                        Regex reg = new Regex(" ");
                        string[] tempStrArray = reg.Split(buildingMatrix[i, j]);
                        if (currentMaxHeight < int.Parse(tempStrArray[1]))
                        {
                            if (!buildingList.Contains(tempStrArray[0]))
                            {
                                buildingList.Add(tempStrArray[0]);
                            }
                            currentMaxHeight = int.Parse(tempStrArray[1]);
                        }
                    }
                }
            }
            for (int i = 0; i < buildingList.Count; i++)
            {
                Console.Write(buildingList[i].ToString() + " ");
            }
            Console.WriteLine();
        }
    }
}

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