These are the questions that are to be done and submitted on a floppy latest by 10 a.m. on 16th feb.

 

Overnight Programming - MAC++

 

Q1 Mazes and Monsters                                                                              110

Two monsters are placed in a NxN maze. The good monster is placed at the top left corner, whereas the evil one is placed at the bottom right corner of the maze. Each maze cell contains either a 1 or a 0. The monsters walk only up, down, left and right (NOT diagonally), in cells which contain a 1. The monsters are met, if they stand on the same cell. You must find the minimum number of steps each monster should perform in order to meet. Note, that at each turn, both monsters should perform a step (i.e. it is not allowed for a monster to stay at the same position, while the other has performed a step). Also, depending on the maze content, the two monsters may never meet.

Input

      Your program should read the input data from the file INPUT1.TXT as follows:

the first line of the input file contains a positive integer N<=20, designating the side of the square maze.

each of the subsequent N lines contain N numbers separated by a space character. Each number is a 0 or 1. These lines are used to represent the maze.

Output

      Your program should write the output into the file OUTPUT1.TXT as follows :

1.        If it is impossible for the two monsters to meet, the first line of the file should contain the string “NOPATH”.

2.        If there is a “meeting” path, then the first line should contain the minimum number of steps that the monsters should perform in order to meet. The next line contains a set of characters that indicates the path that the good monster should follow.

These characters must be either U (for up), D (for down), L (for left) and R (for right). No space character should be placed between these characters. the next line contains a set of characters that indicates the path that the evil monster should follow. Again, these characters must be U, D, L, or R, whereas no space should be placed between these characters.

 

Example 1

Input

5

0 0 0 0 1

0 0 0 1 0

0 0 1 0 0

0 1 0 0 0

1 0 0 0 0

Output

NOPATH

 

Example 2

Input

5

1 1 1 1 0

1 0 0 0 1

1 0 0 0 1

1 0 0 0 1

1 1 1 1 1

Output

4

DDDD

LLLL

 

 


Q2. Excuses, Excuses!                                                                                                120

Judge Ito is having a problem with people subpoenaed for jury duty giving rather lame excuses in order to avoid serving.  In order to reduce the amount of time required listening to goofy excuses, Judge Ito has asked that you write a program that will search for a list of keywords in a list of excuses identifying lame excuses.  Keywords can be matched in an excuse regardless of case.

Input

Input to your program will consist of multiple sets of data.  Line 1 of each set will contain exactly two integers.  The first number (1 <= K <= 20) defines the number of keywords to be used in the search.  The second number (1 <= E <= 20) defines the number of excuses in the set to be searched.  Lines 2 through K+1 each contain exactly one keyword.  Lines K+2 through K+1+E each contain exactly one excuse.  All keywords in the keyword list will contain only contiguous lower case alphabetic characters of length L (1 <= L <= 20) and will occupy columns 1 through L in the input line.  All excuses can contain any upper or lower case alphanumeric character, a space, or any of the following punctuation marks [".,!?] not including the square brackets and will not exceed 70 characters in length.  Excuses will contain at least 1 non-space character.

Output

For each input set, you are to print the worst excuse(s) from the list.  The worst excuse(s) is/are defined as the excuse(s) which contains the largest number of incidences of keywords.  If a keyword occurs more than once in an excuse, each occurrence is considered a separate incidence.  A keyword "occurs" in an excuse if and only if it exists in the string in contiguous form and is delimited by the beginning or end of the line or any non-alphabetic character or a space.

For each set of input, you are to print a single line with the number of the set immediately after the string "Excuse Set #".  (See the Sample Output).  The following line(s) is/are to contain the worst excuse(s) one per line exactly as read in.  If there is more than one worst excuse, you may print them in any order.  After each set of output, you should print a blank line.

Example

Input

5 3

dog

ate

homework

canary

died

My dog ate my homework.

Can you believe my dog died after eating my canary... AND MY HOMEWORK?

This excuse is so good that it contain 0 keywords.

 

6 5

superhighway

crazy

thermonuclear

bedroom

war

building

I am having a superhighway built in my bedroom.

I am actually crazy.

1234567890.....,,,,,0987654321?????!!!!!!

There was a thermonuclear war!

I ate my dog, my canary, and my homework ... note outdated keywords?

 

Output

Excuse Set #1

Can you believe my dog died after eating my canary... AND MY HOMEWORK?

 

Excuse Set #2

I am having a superhighway built in my bedroom.

There was a thermonuclear war!

Q3  Simple Text editor                                                                                     120        

                Make a text editor which should be menu-driven and be able to do the following :

1) Enter Several lines of text and store it in a file.

2) List the data file  with its line numbers

3) Retrieve and display a particular line  etermined by number

4) Insert and delete N lines

5) Save newly edited text

6) Search  for a string and display its location by line number and column number

               

Q4  Scientific Calculator                                                                                                             100

               Make a scientific  calculator with Graphic display with following functions in the form of buttons

1) All basic functions of calculator  like addition subtraction etc

2) Should find Trignometric , Logarithmic and exponential functions

3) It should also contain the various memory functions found in a basic calculator

 

Q5. Calendar                                                                                                                        100

Make a calendar such that :

1.        The current month and year is displayed in the format given below (note : take current year as base year).

2.        The user should be able to scroll through the year and the various months using arrow keys as follows:

Up key to show the next year same month

Down key to show the previous year  same month

Right key to show the next month of the same year

Left key to show the previous month of the same year

Sample Output

------------------------------------------------------------------------

Year name                Month name

------------------------------------------------------------------------

Sun         Mon                 Tue                 Wed                 Thr                Fri                 Sat     

                                  1                   2                   3                   4                   5

6              7                8                   9                10                11                12

13            14                15                16                17                18                19

20            21                22                23                24                25                26

27            28                29                30   

------------------------------------------------------------------------

 

Q6. Transformations                                                                                 110

A square pattern of black and white tiles is transformed into another square. Write a program that will recognise the minimum transformation that has been applied to the original pattern given the following list of possible transformations:

90 Degree Rotation: The pattern was rotated to the right 90 degrees.

180 Degree Rotation: The pattern was rotated to the right 180 degrees.

270 Degree Rotation: The pattern was rotated to the right 270 degrees.

                Vertical Reflection: The pattern was reflected vertically. (See example 4.)

Combination: The pattern was reflected vertically and then subjected to one of the rotations.

                No Change: The original pattern was not changed.

Invalid Transformation: The new pattern was not obtained by any of the above methods.

Input

The input file will consist of a number n (between 1 and 10 inclusive), the size of the square, followed by n lines of the original pattern, and then after a blank line, the n lines of the transformed pattern. Black squares will be indicated by a ‘.’, and white squares by an ‘X’.

 

Output

The output from your program will be a phrase describing the transformation that changed the original pattern to the new pattern. If more than one transformation is possible, then your program should show the transformation corresponding to the minimal amount of work necessary to convert the original pattern to the new pattern. For the purposes of evaluating the amount of work needed, rotations are considered less work than reflections, and smaller rotations are less work than larger ones.

 

Note that only the above possibilities should be considered - there is no such thing as a 360 Rotation, nor is there a horizontal reflection. Also remember that if a single rotation is not sufficient, your program should consider a reflection followed by a rotation.

 

Example 1

Input

5

X             .               .               .               X

.               X             .               .               .

.               .               .               X             .

.               .               X             .               X

.               .               .               .               X

-------------------------------------------------

.               .               .               .               X

.               .               .               X             .

.               X             .               .               .

.               .               X             .               .

X             X             .               .               X

 

Output

ROTATED 270 DEGREES.

 

Example 3

Input

2

X             .

.               X

--------------

X             .

.               X

 

Output

NOT TRANSFORMED

 

Example 4

Input

4

.               .               X             .

X             X             .               .

.               .               .               .              

.               .               .               X

------------------------------------

.               .               .               X

.               .               .               .

X             X             .               .

.               .               X             .

 
Output

REFLECTED.

Example 5

Input

5

X             .               .               .               .

.               X             .               .               .

.               X             .               .               .

.               .               .               X             .

.               .               .               .               X

-----------------------------------------------

.               X             .               .               .

.               .               X             .               .

.               .               X             .               .

.               .               .               .               X

X             .               .               .               .

 

Output

IMPROPER TRANSFORMATION.

 

Example 6

Input

4

.               X             .               .

.               X             .               X

.               .               .               .

.               .               X             .

-------------------------------------

.               .               X             .

X             .               .               .

.               .               X             X

.               .               .               .

 

Output

REFLECTED AND ROTATED 270 DEGREES

 

 


Q7. Greedy Gift Givers                                                                                    80

You are to determine, for a group of gift-giving friends, how much more each person gives than they receive (and vice versa for those that view gift-giving with cynicism). In this problem each person sets aside some money for gift-giving and divides this money evenly among all those to whom gifts are given. However, in any group of friends, some people are more giving than others (or at least may have more acquaintances) and some people have more money than others.

Given a group of friends, the money each person in the group spends on gifts, and a (sub)list of friends to whom each person gives gifts; you are to write a program that determines how much more (or less) each person in the group gives than they receive.

Input

The input is a group of gift-givers which consists of several lines:

1.        the number of people in the group,

2.        a list of the names of each person in the group,

3.        a line for each person in the group consisting of the name of the person,the amount of money spent on gifts, the number ofpeople to whom gifts are given, and the names of those to whom gifts are given.

4.        All names are lower-case letters, there are no more than 10 people in a group, and no name is more than 12 characters in length. Money is a non-negative integer less than 2000.

 

Output

The name of each person in the group should be printed on a line followed by the net gain (or loss) received (or spent) by the person. Names in a group should be printed in the same order in which they first appear in the input.

All gifts are integers. Each person gives the same integer amount of money to each friend to whom any money is given, and gives as much as possible. Any money not given is kept and is part of a person's “net worth” printed in the output.

Example 1

Input

5

dave laura owen vick amr

dave 200 3 laura owen vick

owen 500 1 dave

amr 150 2 vick owen

laura 0 2 amr vick

vick 0 0

Output

dave 302

laura 66

owen -359

vick 141

amr -150

 

Example 2

Input

3

liz steve dave

liz 30 1 steve

steve 55 2 liz dave

dave 0 2 steve liz

Output

liz -3

steve -24

dave 27

 

 


Q8. Word Match                                                                                  80

As a secret service agent, you monitor all computer email traffic, searching for keywords that suggest subversive activities.  However, some subversive elements in society have started scrambling the letters in some words of their email messages in an attempt to evade detection.

You, undeterred by such transparent tricks, decide to write a program that searches sentences for suspicous words whose letters have been rearranged.

INPUT

The input contains pairs of lists and sentences. The list gives the words to search for in the following sentence. All letters in the input are in lower case. Words are at most 20 letters long and are seperated by a single space. Each line is at most 80 characters long. Each list fits on a single line and contains at most 20 words. Sentences may occupy more than one line, and are terminated by a full stop.

The end of input is denoted by a list containing only a #.

OUTPUT

For each pair of list and sentence, find the words from the list that appear in the sentence with their letters shuffled. Print these words in the order they appear in the list, separated by a single space. If no words from the list match the words in the sentence, just print a blank line.

 

SAMPLE INPUT

bomb

we twan ot ombb mericaa.

guns mines missiles

aameric ssell snug

dan iimsssle ot sit neeemis.

cat sat mat

cat sat tam mat.

#

 

SAMPLE OUTPUT

bomb

guns missiles

cat sat mat