Programming Program for Information Processing (Sample Programming Problems)

          Sample Programming Problems

The following are three sample problems. The first two problems are considerably easier than the third one.

Perfect Numbers

A perfect number is an integer that is equal to the sum of all of its factors other than itself. For example, 28 is a perfect number since 1+2+4+7+14=28. Write a program that reads in an integer, say N, and reports all the perfect numbers in the range 1..N.Sample Input:
10000
Sample Output:
6
28
496
8128

Legal Words

(from UCF Local Contest)You are to write a program which reads a list of words and determines which of them is illegal. A word is illegal if it contains no vowels. For this problem, the letter Y is considered to be a legal vowel.
The Input: The data set will consist of a list of words, one per input line. Each word will consist of at least one and at most 20 letters. The letters may be capital or lower case. Assume that each word starts in column 1 and that there are only letters in a word.
The Output: For each word, print: word is legal or word is not legal whichever is appropriate, where word is the actual word. Print one message per line.
Sample Input
These
test
Mr
Miss
sch
Sample Output
These is legal.
test is legal.
Mr is not legal.
Miss is legal.
sch is not legal.

Phoney Programming

(from UCF local contest)A standard telephone has both numbers and letters on its keys. Each of the ten number keys has the letters associated as follows:

1,0: Have no corresponding letters
2:   A B C
3:   D E F
4:   G H I
5:   J K L
6:   M N O
7:   P R S
8:   T U V
9:   W X Y
Given a phone number, display all the permutations formed from the letters represented by the corresponding numbers of the last four digits of the phone number. The digits and should not be replaced.
The Input: The phone number starts in column one and will be in the form ``ddd-dddd''. The phone number is contained on one line.
The Output: The program should print the total number of permutations, followed by the permutations (one permutation per line). Order within a data set is not important.
Sample Input:
422-0990
Sample Output:
Total number of permutations = 9
0WW0
0WX0
0WY0
0XW0
OXX0
0XY0
0YW0
0YX0
0YY0


Soucre: http://cs.boisestate.edu/~amit/prog-contest/sample-problems.html#problem3

Walang komento:

Mag-post ng isang Komento