Algorithm Assignmedxgfxgx+nt Statements



Comments



Description

A trip to MarsA squad of robotic rovers are to be landed by NASA on a plateau on Mars. This plateau, which is curiously rectangular, must be navigated by the rovers so that their on-board cameras can get a complete view of the surrounding terrain to send back to Earth. A rover’s location and position is represented by a combination of x and y coordinates and a letter representing one of the four cardinal compass points. The plateau is divided up into a grid to simplify navigation. An example position might be 0, 0, S, which means the rover is in the upper-left corner and facing South. In order to instruct a rover to move forward in the direction its facing, NASA sends a simple string comprising of a sequence of 'M'. Each ‘M’ means move forward one grid point if the point lies in the limits of the grid, otherwise remain in the same position without moving forward, and maintain the same heading direction and throw an error message indicating the point lies out of the defined limits. Assume that the location directly South from (x, y) is (x, y+1), where x is the horizontal axis and y is the vertical axis. Also assume the directions are as per the diagram below: Input Specification  First line of the input is the lower-right coordinates of the plateau, and the upper-left coordinates are assumed to be 0, 0.  Second line of the input gives the coordinates representing the position of the rover on the grid and its heading direction  Next line is a series of 'M' telling the rover to explore the plateau by moving one location for each 'M'. Output Specification  Print the final coordinates with the direction of heading of the rover, all separated by a space, otherwise throw the error message if the location coordinates land beyond the given defined boundary and print the present coordinates. Sample Input1 Sample Output1 Sample Input2 Sample Output2 55 12N MM 10N 55 12N MMM 12N OutOfBoundsException 2. 1000 are coming immediately below of -1 then 5000 should be added to 1000. 1000. Your programme should ask to enter a number between 0 and 10000 (excluding 0 and 10000) and output the resultant matrix representing the entered number. 1000 and 1000 (5000+1000+1000+1000) and the result will be 8000. Write a programme which will represent a given number between 0 and 10000 by the matrix just explained in previous page. The procedure of reading the matrix is given below: • In each column the numbers coming between -1 and 0 (both above -1 and below -1) will be added. the results of all the four columns will be added to get the number represented by the matrix.Abacus – I Consider the 8 * 4 (8 rows 4 columns ) matrix given below.e it is representing the number 0 (Zero). Input specification :A number between 0 and 10000 Output specification :The matrix representing the number. 100. Print each row of the matrix in a new line with the contents of the row seperated by a double space. The matrix contains two all zeros rows and one all -1 rows . 500. 3 and 4 respectively and one row is having values 5000. So the number represented by the matrix shown above is 7000+700+50+8 = 7758. The result of fourth column is 5+1+1+1 = 8. For example the matrix given below is representing the number 7758 0 0 0 0 5000 500 50 5 -1 -1 -1 -1 1000 100 0 1 1000 100 10 1 0 0 10 1 1000 100 10 0 1000 100 10 1 • The result of first column is 5000+1000+1000 = 7000. 10 and 1 for the columns 1. For example :0 0 0 0 5000 500 50 5 -1 -1 -1 -1 1000 100 0 1 1000 100 10 1 0 0 10 1 1000 100 10 0 1000 100 10 1 . The result of second column is 500+100+100 = 700. Refer to the column representation below:0 5000 -1 1000 1000 1000 0 1000 • After finding the result of all the four columns using the procedure mentioned above . 5000 500 50 5 0 0 0 0 -1 -1 -1 -1 0 0 0 0 1000 100 10 1 1000 100 10 1 1000 100 10 1 1000 100 10 1 We can represent any positive number between 0 and 10000 using the matrix explained above. Four rows are having values 1000. The matrix represented above is at the initial or zero state i. Remember you have to add till 0 only. The result of third column is 50. 50 and 5. For example for first column if 5000 is coming immediately above -1 and 1000. 2. The matrix represented above is at the initial or zero state i. Write a programme which will output a number represented by the matrix just explained in the previous page.e it is representing the number 0 (Zero). Input specification The matrix representing the number. Remember you have to add the numbers till 0 only. The result of second column is 500+100+100 = 700. Refer to the column representation below:0 5000 -1 1000 1000 1000 0 1000 • After finding the result of all the four columns using the procedure mentioned above . The procedure of reading the matrix is given below:• In each column the numbers coming between -1 and 0 (both above -1 and below -1) will be added. So the number represented by the matrix shown above is 7000+700+50+8 = 7758. Your programme should ask to enter the contents of the 8 * 4 (8 rows 4 column) matrix and then display the output represented by the entered matrix. 3 and 4 respectively and one row is having values 5000. The matrix contains two all zeros rows and one all -1 rows . For example for first column if 5000 is coming immediately above -1 and 1000. 1000. For example :0 0 0 0 5000 500 50 5 -1 -1 -1 -1 1000 100 0 1 1000 100 10 1 0 0 10 1 1000 100 10 0 1000 100 10 1 Output specification The number represented by the entered matrix. . 100. The result of fourth column is 5+1+1+1 = 8. The result of third column is 50. For example for the matrix entered above the number should be 7758. For example the matrix given below is representing the number 7758 0 0 0 0 5000 500 50 5 -1 -1 -1 -1 1000 100 0 1 1000 100 10 1 0 0 10 1 1000 100 10 0 1000 100 10 1 • The result of first column is 5000+1000+1000 = 7000. 500. 50 and 5. the results of all the four columns will be added to get the number represented by the matrix. Four rows are having values 1000.Abacus – II Consider the 8 * 4 (8 rows 4 columns ) matrix given below.                      5000 500 50 5 0 0 0 0 -1 -1 -1 -1 0 0 0 0 1000 100 10 1 1000 100 10 1 1000 100 10 1 1000 100 10 1 We can represent any positive number between 0 and 10000 using the matrix explained above. 1000 and 1000 (5000+1000+1000+1000) and the result will be 8000. Enter each row of the matrix in a new line with the contents of the row seperated by a single space. 1000 are coming immediately below of -1 then 5000 should be added to 1000. 10 and 1 for the columns 1. The string BALL is represented horizontally in the same row which is containing the common character 'A'. That means the co-ordinate of first character of string CAT i. SampleInput 1 SampleOutput 1 CAT 1 2 BALL * * * * * * * * * * * * * * C * B A L * T * * * * * * * * * * * * * * * * * * * * * L * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * SampleInput 2 SampleOutput 2 INDIA 3 5 GOA * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * I * * N * * D * * I G O A * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * . b) Both the strings remain within the bounds of 10 * 10 matrix. • Each row of the matrix should be terminated by a new line and the contents of the row be seperated by a single space. The first character of the string CAT is represented at first row and second column (1. c) There is one and only one same character among the two strings.CrossWord Consider the 5 * 5 (5 rows and 5 columns) matrix given below :0 1 2 3 4 0 * * * * * 1 2 3 * * * * C * B A L * T * * * * 4 * * L * * The matrix shown above is containing two words CAT and BALL. There is a common character between string CAT and string BALL. The representation of the second string BALL is based upon the common character 'A'.2). The common character is 'A'. CAT is printed vertically and BALL is printed horizontally. For example :Assumptions: a) The strings length will be >= 3 and <= 5.e 'A' and 'T' are placed vertically just below the first character 'C' in the same column. Rest of the elements are represented by '*' only. The remaining characters of the string CAT i.2). Write a program which accepts two strings as input and represents them in a 10 * 10 matrix in the similar manner as explained above. Input specification: • First line of the input comprises of the string to be placed vertically and followed by a space. then followed by the space separated coordinates indicating the location of the first character of the string • Second line of the input comprises of the string to be placed horizontally intersecting with the string placed vertically Output specification: • The 10 * 10 matrix with both the strings placed appropriately.e 'C' is (1. And the remaining of the matrix contents should be represented by the character '*'. 49 (=7^2). s2. The number of iterations i required for these to reach 1 are..Happy Numbers Let the sum of the squares of the digits of a positive integer s 0 be represented by s1. 4. 10. then the original integer s 0 is said to be happy. 1 (=1^2). 37. Input Specification  It is a single line input of two positive integers separated by a space.. 58. 32. Sample Input 7 11 Sample Input 44 68 Sample Output 76 10 2 Sample Output 44 5 49 5 68 3 . Output Specification  Print all happy numbers in the interval and the number of iterations required by it to reach 1. 79. Unhappy numbers have eventually periodic sequences of s i which do not reach 1 (e. let the sum of the squares of the digits of s 1 be represented by s 2. You need to write a program to find all the happy numbers in a given closed interval.). 20. . 4. In a similar way. 70. 91. For example. which reaches 1 on 6 iterations. 23. 68. …. 42. 13. 16. 7. so 7 is a happy number. starting with 7 gives the sequence 7. 10 (=1^2+3^2). s3.. 97 (=4^2+9^2). 97. 5. If s i=1 for some 1≤ i. 89. 49. 5. then any number in the sequence s1. The first few happy numbers are 1.. 44. separated by a space and each in a new line. 145.. 5. .. 4. and so on. which reach 1 within 10 iterations. . 4.. 4. 86. Once it is known whether a number is happy (unhappy). 19. 3. respectively.g. 2.. 100. 94. A number that is not happy is called unhappy. 130 (=9^2+7^2). will also be happy (unhappy). 31. 82. 28. 6. 1. 3. 3. then your program should output the lexicographically first largest palindrome. If the string contains two palindromes. A word is called a palindrome if it reads the same when you reverse it. which are equal in length and are the largest among all possible palindromes in the string. Your program should take an input as a string and produce the largest palindrome in the string. and has a phonetical value. Input Specification  It is a single line input of a string.The Palindrome A word is a unit of language that carries meaning and consists of one or more morphemes which are linked more or less tightly together. Output Specification  Print the largest and lexicographically first palindrome in the string. Sample Input Sample Input dearmadamdear database Sample Output madam Sample Output aba . on a new line. To accommodate all alphabets. to type certain characters. A word is formed by the letters A-Z and a-z and has at most 40 letters. Here SP means a space. two for ‘e’ and three for ‘f’. Therefore. Note that it takes a single press to type a space. The only symbols that appear in the input are the alphabetic letters and white spaces. Sample Input welcome to ulab Sample output 29 . This is also applicable for the remaining keys and letters. Input Specification  The first line of input will be a set of Words. In the same manner. In this problem we will assume that the keypad of our cell phone is arranged as follows. a key must be repeatedly pressed until that character is shown on the display panel. most cell phones have limited number of keys. In this problem we are interested in finding out the number of times keys on a cell phone must be pressed to type a particular message.The keypad of an antique Cellphone Cell phones have become an essential part of modern life. letters are compacted into single key. In addition to making voice calls. one key press for ‘d’. we must press that key once. however to type ‘b’ the same key must be repeatedly pressed twice and for ‘c’ three times. cell phones can be used to send text messages. Unlike computer keyboards. In order to type the letter ‘a’. which are known as SMS for short. Output Specification  Print the number of key presses required to type the message and terminated by new line character. In the above grid each cell represents one key.
Copyright © 2024 DOKUMEN.SITE Inc.