Sunteți pe pagina 1din 4

University of Cebu – Main Campus

Computer Engineering Department

Programmer of the Year 2018 Contest


Easy Problems:

Problem 1:
Write a program that will:
o Accept alphanumeric string (maximum of 50 characters)
o Compute and display the summation of the all the numeric characters found in the given
string.
Sample output:
Input String: joy 2 the world 4 8 may make us happy
Output: 14 (from 2+4+8)

Problem 2:

Write a complete program that will correctly decode a set of characters into a valid message. Your
program should read a given file of a simple coded set of characters and print the exact message that
the characters contain. The code key for this simple coding is a one for one character substitution
based upon a single arithmetic manipulation of the printable portion of the ASCII character set.

Input and Output

For example: with the input file that contains:

1JKJ'pz'{ol'{yhklthyr'vm'{ol'Jvu{yvs'Kh{h'Jvywvyh{pvu5

Output:

*CDC is the trademark of the Control Data Corporation.

Average Problems:

Problem 1:

(Displaying an Integer with Commas)


Write a program that prompts the user for an integer. It then displays the integer (and an explanatory
string) with commas between every set of three digits. Your program must have the following
properties.
. The solution must be able to handle arbitrarily large integer values. You can not assume that the
integer has at most some specific finite number of digits (such as nine). For example, if the maximum
size of the int data type were to be increased on a new machine, your program should not fail.
. You must read in and process the integer as an integer, not as a string.
. Your program output must look like the example output shown below. User input is shown in italics
and program output is shown in boldface.
Example Program Run 1
Please enter one integer: 123456789
The integer with commas is 123,456,789
Example Program Run 2
Please enter one integer: 12345
The integer with commas is 12,345
Example Program Run 3
Please enter one integer: 12
The integer with commas is 12

(Rock, Paper, Scissors)

Problem 2:

Write a program that plays the game Rock−Paper−Scissors with the user until the user does not want
to play any longer. In a single game the user makes a choice of rock, paper, or scissors and the
computer does also. The computer’s choice is made randomly. Rock beats scissors, scissors beats
paper, and paper beats rock.
Your program must have the following properties.
. When your program prompts the user about playing another game, your program must handle the
user entering an invalid value (that is, not yes or no) by detecting that the value is invalid and
repeating the prompt until a valid answer is given by the user.
. When your program prompts the user about making a choice of rock, paper, or scissors, your
program must handle the user entering an invalid value by detecting that the value is invalid and
repeating the prompt until a valid answer is given by the user.
. The computer’s choice must be generated randomly
. Your program output must look like the example output shown below (except that because the
computer’s choice is randomly generated, its choice may differ). User input is shown in italics and
program output is shown in boldface.

Example Program Run 1


Do you want to play a game of Rock−Paper−Scissors (yes/no)? maybe
Your answer was not yes or no. Please try again: yes
Please enter your choice of rock, paper, or scissors: rock
Computer wins. user == rock; computer == paper

Do you want to play a game of Rock−Paper−Scissors (yes/no)? yes


Please enter your choice of rock, paper, or scissors: rock
Tie. user == rock; computer == rock

Do you want to play a game of Rock−Paper−Scissors (yes/no)? yes


Please enter your choice of rock, paper, or scissors: stone
Your choice was not rock, paper, or scissors. Please try again: scissors
User wins. user == scissors; computer == paper

Do you want to play a game of Rock−Paper−Scissors (yes/no)? no


Thanks for playing.

Difficult Problem:
Problem 1:

Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make
changes with these coins for a given amount of money.

For example, if we have 11 cents, then we can make changes with one 10-cent coin and one 1-cent
coin, two 5-cent coins and one 1-cent coin, one 5-cent coin and six 1-cent coins, or eleven 1-cent
coins. So there are four ways of making changes for 11 cents with the above coins. Note that we
count that there is one way of making change for zero cent.

Write a program to find the total number of different ways of making changes for any amount of
money in cents. Your program should be able to handle up to 7489 cents.

Input
The input consists of a number for the amount of money in cents.

Output
output a line containing the number of different ways of making changes with the above 5 types of
coins

Sample Input
11 --- (10-1, 1-1) (5-2, 1-1) (5-1, 1-6), (1-11)

Sample Output
4

Problem 2

Tag balance checker.

Tags are keywords used in HTML and XML document. Normal tags contains start tag (ie <body>) and
end tag </body>. These are some of the examples of HTML tags:

<body> </body> <head> </head>, <p> </p>

Write a program to accept series of tags and validate if the tag is balance or un-balance tag. Balance
tag are tags wit start and end tag.

Sample 1
Enter series of tags:
<body> <head> <p> </p> <bold> </bold></head> </body>

Output
Balanced tag
Sample
Enter series of tags:
<body> <head> </p> <bold> </head> </body>

Output
Un-balanced tag

S-ar putea să vă placă și