Site Navigation

Home
 
My Programs
 

     C# Classes

     VB 6.0 Programs

     C Programs

     C Games

Articles

My Blog

Page for Classmates

Programs by Others

Programming Problems

     Software Competitions


Programming Forum

Sign my Guestbook

View my Guestbook

Email me

 

International Computer Programming Competition

Kuala Lumpur

August 10, 1992

FINAL

 

Program 1

Diamond Pattern

A 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 2

Arithmetic Evaluation

Write 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 3

Alphabet Statistics

You 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

  1. calculate the occurrences of each letter in the input string, i.e. the number of times each letter appears in the string;

  2. calculate the average of the occurrences of the letters using the following formula:
    average occurrence = (the length of the string) / (the number of different alphabets appeared in the string)

  3. truncate the average to an integer; and

  4. display the occurrences of each letter in a bar chart

Your bar chart should follow the following format:

Let n be the truncated average occurrence.

Suppose a letter A occurs k number of times.

If n is less than k, the bar for A will have k-n number of pluses (+s) above the axis.

If n is equal to k, there will be no bar for A.

If n is greater than k, the bar for A will have n-k number of minuses(-s) below the axis.

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 4

Matrix Manipulation

You 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:

  1. The main diagonal : elements of the diagonal which starts from the top left hand corner of the matrix.

  2. The secondary diagonal : elements of the diagonal which starts from the top right hand corner of the matrix.

  3. The top triangle : elements above the main and the secondary diagonals.

  4. The bottom triangle : elements below the main and the secondary diagonals.

  5. The left triangle : elements below the main triangle and above the secondary diagonal.

  6. The right triangle : elements above the main diagonal and below the secondary diagonal.

 

Write a program to exchange

  1. the elements of the main diagonal with the elements of the secondary diagonal;

  2. the elements of the top triangle with the elements of the bottom triangle; and

  3. the elements of the left triangle with the elements of the right triangle;

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