Site Navigation
|
International Software Competition 92Venue: Singapore25 November 92
Program 1Addition Of Long IntegersWrite a program to perform the addition of two long integers. A long integer has at most 50 digits and it could be positive, negative or zero. Your program should read in two strings for the two long integers. For negative integers, the sign is given at the leftmost character. There is no sign for positive integers. Your program should then print out the two long integers and their sum in the format as shown in the sample output below.
Sample Input: 10 DATA 13579 20 DATA -123456789012345678901234567890
Sample Output: 13579 -123456789012345678901234567890 (+) ----------------------------------- -123456789012345678901234554311
Program 2Repeating String PatternsYou are to write a program to read in a string of letters and print out in alphabetical order, all the repeating string patterns that can be found in the main string. The lengths of the repeating string patterns must at least be 2 characters. If no such pattern can be found in the given string, the program should print out No repeating string pattern. Otherwise, it should print out the sorted list of repeating string patterns within 60 columns and a space is used to separate two strings. If a string pattern cannot be fitted into the same line, it should be printed on the next line. Each repeating string pattern should only be printed once. You may assume that the length of the given string is not more than 20 characters and its letters are all in lower case.
Sample Input: 10 Data mississmississm
Sample Output: is iss issi issis ississ ississm issm mi mis miss missi missis mississ mississm si sis siss sissm s mss ssi ssis ssiss ssissm
Program 3Regions of a Square ArrayA square array of size n (3 ≤ n ≤ 20) may be divided into various regions with vertical lines, horizontal lines and/or near diagonal lines. You are to write a program to fill a square array with 0s and ls such that adjacent regions in the array are filled with different digits, with the left uppermost region filled with 0s. Two regions are adjacent if they share a common side. The following diagram shows all the possible lines that can be used to divide a square array of size 5 into regions.
For any square array, there are always only two possible near diagonal lines, namely line A and B. A near diagonal line is one that is drawn along a diagonal of the square array such that the diagonal array elements are in the region above the line. If the above square array is divided using only five lines, namely H1, H3, V2, A and B, it should be filled as follows:
Your program should read in the size of the square array and a string for the dividing line(s) (there is at least one dividing line). The order in which the lines are given in the string is not fixed. Then it should print the array which is filled with 0s and ls. You may assume that the data provided in the DATA statement is correct.
Sample Input: 10 DATA 5, ABH1V2H3
Sample Output: 00111 01001 00011 10110
Program 4Commander and SoldiersAmong 13 soldiers, there are 5 whom the commander wants to punish. He wants it to appear as if the soldiers to be punished are chosen at random. He asks the soldiers to arrange themselves into a circle. Taking the positions of the 5 soldiers into account,- he starts counting from a certain soldier and counts around the circle clockwise by a fixed interval until the first 5 soldiers are counted out to be punished. Suppose the soldiers arrange themselves into a circle as shown below and the 5 to be punished are at positions 3, 4, 8, 9 and 12:
In order for the commander to count out the 5 soldiers for punishment, he can start counting from a certain soldier with an appropriate counting interval. For example, he can start counting from soldier 1 with a counting interval of 4. Then the first soldier counted out will be soldier 4, followed by soldiers 8, 12, 3 and 9. Note that those soldiers who are already counted out will not be counted again. Write a program to read in 5 integers for the positions of the 5 soldiers in the circle whom the commander wants to punish. Then your program should print out the smallest counting interval that the commander can choose and the soldier he should start counting from, in order to count out the 5 soldiers. In addition, print out the order in which these soldiers are counted out. You may assume that the integers given in the DATA statement are correct and in increasing order.
Sample Input: 10 DATA 1, 2, 5, 8, 11
Sample Output: Smallest interval: 3 Start counting from soldier: 13 The five soldiers are counted out in this order: 2, 5, 8, 11, 1 |