Site Navigation
|
International Computer Programming CompetitionKuala LumpurAugust 10, 1992FINALProgram 1Diamond PatternA diamond pattern is formed by six triangles of the same size. The top three triangles are symmetrical to the bottom three with respect to the arrangement of letters. The top most triangle is supported by two triangles. The triangle on the right is in reverse order of the left triangle as far as the arrangement of the letters are concerned. Each triangle is formed with the letters of a given string. The figure in the sample output shows a pattern having six triangles formed by the letters of the string KUALA Assume that the length of the string given in the data statement to form the pattern is not more than six characters. Write a program to output the pattern starting from column 40 at the top of a cleared screen. The string to be used to form the pattern is given in a DATA statement and assume that there are no empty spaces embedded in the string. On pressing the RETURN key, your program should clear the screen and display a new but similar pattern with asterisks replacing all the letters that formed the edges of the earlier pattern. Note that there should be single spaces between the letters on the same line in the pattern.
SAMPLE DATA 10 DATA KUALA
SAMPLE OUTPUT K K U K U A K U A L K U A L A K K K U U K K U A A U K K U A L L A U K K U A L A A L A U K K U A L A A L A U K K U A L L A U K K U A A U K K U U K K K K U A L A K U A L K U A K U K
(On pressing the RETURN key the following pattern should be displayed)
* * * * U * * U A * * * * * * * * * * * * * U * * U * * U A * * A U * * U A L * * L A U * * U A L * * L A U * * U A * * A U * * U * * U * * * * * * * * * * * * * U A * * U * * * *
Program 2Arithmetic EvaluationWrite a program to evaluate a given arithmetic expression in a DATA statement. The expression is formulated using the following: 1) Signed integer constants (-32768 to +32767). Unsigned integer numbers are assumed as positive. 2) Symbols +, -, / and * stand for addition, subtraction, division and multiplication respectively. All the symbols are given equal priority and the expression is evaluated from left to right. The division symbol (/) implies real division (not the integer division). The evaluation should give the result in real number which should be rounded to two decimal places.
Following are examples of valid expressions and their evaluated values: 20*3+4-1/3 = 21.00 10-5*4/3/2+1 = 4.33 2--2 = 4.00 5++1-2*-2 = -8.00 12-7*4/3 = 6.67 The expression to be evaluated is given in a DATA statement in a form of a string. Assume that all given expressions are valid expressions and there are no empty spaces embedded within the expression.
SAMPLE INPUT 10 DATA 20*3+4-1/3
SAMPLE OUTPUT The expression: 20*3+4-1/3 = 21.00
Program 3Alphabet StatisticsYou are given a string which is composed of upper case alphabets and not exceeding 60 characters in a DATA statement. Assume that there are no empty spaces embedded in the string. Write a program to
Your bar chart should follow the following format:
The horizontal axis is formed by the letters representing the bars and should be displayed on the 12th row of the screen starting from the 5th column. The arrangement of the letters along the axis is based on the number of occurrences of the letters in ascending order, i.e. the letter with the least number of occurrence will appear first. Use the first three. columns to display the scale of the vertical axis which range from +11 to -11 (right justified), please refer to the sample output. Assume that the difference between the average occurrence and the highest/lowest occurrence is not greater than 11.
SAMPLE DATA 10 DATA AAADEEEAAAABBBBBBCBCCCBBBBBBBBCCCCCCC
SAMPLE OUTPUT 11 10 9 8 + 7 + 6 + 5 + 4 + + 3 + + 2 + + 1 + + 0 D E A C B -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 11
Program 4Matrix ManipulationYou are given a two dimensional array with N rows and N columns, where N is odd and not exceeding 23. The elements of the matrix can be grouped as follows:
Write a program to exchange
and display the resultant matrix. In the output, there should be only one blank space between the row elements. The elements of the matrix should be displayed row by row, i.e. the values displayed in the first line are the values of the elements of the first row of the resultant matrix. Note that the exchanges of places between groups are done on elements which are symmetrically opposite as illustrated in the sample. The first DATA statement should contain only the size of the matrix and the following DATA statement(s) should contain the elements of the matrix row by row.
SAMPLE DATA 1 10 DATA 5 15 DATA 1, 2, 3, 4, 5 20 DATA 6, 7, 8, 9, 10 25 DATA 11,12,13,14,15 30 DATA 16,17,18,19,20 35 DATA 21,22,23,24,25
SAMPLE OUTPUT 1 5 22 23 24 1 10 9 18 7 6 15 14 13 12 11 20 19 8 17 16 25 2 3 4 21
SAMPLE DATA 2 10 DATA 3 15 DATA 2,3,7 20 DATA 4,5,8 25 DATA 9, 10, 1 1
SAMPLE OUTPUT 2 7 10 2 8 5 4 11 3 9 |