Site Navigation
|
International Software Competition 90Venue: National Computer Board, SingaporeDate: 12 December 1990
Program 1Spiral
Write a program to display, on a cleared screen, a pattern of asterisks in the form of a clockwise square spiral. The figure shows a spiral of size 9, which is the number of asterisks in the longest row
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
The pattern starts with 1 asterisk and continues with 2 more asterisks vertically (downwards), then 3 more asterisks horizontally, and so on. Each time the number of asterisks is increased, the spiral makes a turn of 90 degrees clockwise. The first five steps to form the spiral pattern are shown below: Size 1 *
Size 2 * * *
Size 3 * * * * * *
Size 4
* * * * * * * * * *
Size 5
* * * * * * * * * * * * * * *
The size of the spiral to be displayed is given in a DATA statement as an integer which will not be greater than 20.
SAMPLE DATA 10 DATA 8
SAMPLE OUTPUT * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Program 2Multiple ChoiceA Multiple Choice test consists of N questions, each with a choice of several answers, only one of which is right. Write a program to grade the test for a number of students (the number denoted by NS) and print each students name, the number of correct answers and the students final percentage mark. The students names are to be displayed in alphabetical order and percentage marks are to be rounded correct to 1 decimal place. The final .percentage mark is calculated using the formula: ( Number answered correctly ) / N * 100 % The DATA statements consist of the following: 1) one line giving N, the number of questions 2) one line of N integers for the correct answers (answer key) 3) one line giving the number of students (NS) in the class 4) NS lines, one for each student giving his/her name and the N answers.
SAMPLE DATA 10 DATA 6 15 DATA 1,4,5,2,2,1 20 DATA 10 21 DATA CHARLIE, 2,3,4,5,1,2 22 DATA FOXTROT, 1,1,5,2,1,1 23 DATA ABLE, 1,5,5,2,3,1 24 DATA GEORGE, 2,4,5,2,2,1 25 DATA HELSINKI, 1,4,5,2,2,1 26 DATA BAKER, 1,1,2,2,3,5 27 DATA ICELAND, 1,2,3,4,1,2 28 DATA JACK, 1,4,5,2,2,1 29 DATA ECHO, 4,4,5,5,2,2 30 DATA DELTA, 4,4,5,1,2,2
SAMPLE OUTPUT
Name No. Correct Percentage ---- ----------- &nbssp; ---------- ABLE 4 66.7 BAKER 2 33.3 CHARLIE 0 0.0 DELTA 3 50.0 ECHO 3 50.0 FOXTROT 4 66.7 GEORGE 5 83.3 HELSINKI 6 100.0 ICELAND 1 16.7 JACK 6 100.0
Program 3Monotonic SequencesIt is often necessary to determine whether a given sequence of N numbers denoted mathematically as X[1], X[2], ,X(N) is, monotonic increasing, monotonic decreasing or neither. The sequence is monotonic increasing if X[I] < X[I+1] for all I= 1,2,...,N-1. That is, consecutive numbers in the sequence are increasing. Similarly, the sequence is monotonic decreasing if X[I] > X[I+1] for all I=l,2,...,N-1; that is consecutive numbers are decreasing. For example, the sequence 1, 2, 6, 10, 12 is monotonic increasing, and the sequence 20, 13, 11, 6, 3, 1 is monotonic decreasing. Write a program that reads a series of positive integers from a DATA statement, then finds and prints the longest monotonic increasing sequence and the longest monotonic decreasing sequence which occur in the given series. For example, given the series: 3, 4, 9, 33, 4, 7, 9, 8, 5, 4, 3, 4, 15 then the longest monotonic increasing sequence is 3, 4, 9 33 and the longest monotonic sequence is 9, 8, 5, 4, 3. The given series in the DATA statement will contain at most 20 integers, and will be such that there is only on 1 longest monotonic increasing sequence and one longest monotonic decreasing sequence.
SAMPLE DATA 10 DATA 3,5,7,2,1,4,6,7,5,3,2,1
SAMPLE OUTPUT THE LONGEST MONOTONIC INCREASING SEQUENCE IS 1, 4, 6, 7 THE LONGEST MONOTONIC DECREASING SEQUENCE IS 7, 5, 3, 2, 1
Program 4Word OrderingAn alphabet comprises only six CAPITAL letters Z,Y,X,A,B,C. Words in this alphabet are sequences of one or more of the six letters, repetitions being allowed. The alphabetical order of this alphabet Is Z,Y,X,A,B,C; the letter Z being the first letter, and C the last letter of the alphabet. Write a program to read in a number (not greater and the words that follow, the number indicating the number of words of the special alphabet to be sorted alphabetically. The given words will all be in CAPITAL letters only, and each word consists of not more than 5 letters of the alphabet. Your program is to display the sorted words on a cleared screen. For example, if the given DATA is 6,X,YX,YY,Z,B,BACXY then sorted words should be displayed in the following format ORDER 1 Z ORDER 2 YY ORDER 3 YX ORDER 4 X ORDER 5 B ORDER 6 BACXY
SAMPLE DATA 10 DATA 5,ACBAC,ZABX,X,XY,ACBBA
SAMPLE OUTPUT ORDER 1 ZABX ORDER 2 X ORDER 3 X ORDER 4 ACBAC ORDER 5 ACBBA |