Computer Contest

advertisement
Programming Contest 2004 (March 13, 2004)
1.
Write a program that reads an integer, and output all the positive integers by which it is
divisible.
For example, if the input is: 12
FACTORS ARE: 1, 2, 3, 4, 6, 12
2.
Write a program that reads four integers and prints out one of the following:
A. "NO MATCHES" if all 4 are different
B. "ONE PAIR" if 2 are the same and the other 3 are different
C. "TWO PAIRS" if 2 numbers are repeated
D. "TRIPLE" if 1 number occurs 3 times and 4th number is different
E. "ALL MATCH" if 1 number occurs 4 times
3.
Write a program to randomly populate a two dimensional grid (10 rows and 10 columns)
with 1s or 0s, and to print out the 10-by-10 grid, one line per row.
No more than 1/5 of the cells should be assigned a 1 value and the cells with 1 values should
be randomly distributed.
4.
Write a program that reads in10 integers and prints out answers for the following 3
questions:
A. the difference of the smallest and the largest
B. how many different integers appear.
C. the length of the longest consecutive increasing subsequence
For examples, if 3, 6, 4, 6, 21, 7, 7, 8, 9, 4 are entered, your program should print out:
(A) LARGEST - SMALLEST = 18
(B) THERE ARE 7 DIFFERENT NUMBERS
(C) THE LONGEST CONSECUTIVE INCREASING SUBSEQUENCE HAS LENGTH 3.
Download