Programming Smackdown! Challenge Problems
1. Pyramid (2 pts)
Write a program that prints a 'pyramid' shape of a specified height on the screen.
Your height must be between 1 and 30
2. Calculating bowling match scores (8 pts)
A bowling match consists of ten frames. Each frame except for the tenth consists of
one or two balls, or attempts to knock down the ten pins at the end of the alley.
Doing so on the first ball of the frame is called a strike, and the second ball of
the frame is not rolled. Knocking down all ten pins with both balls (having left
some up with the first ball) is called a spare. If both attempts to knock down the
pins leave some standing, the frame is called an open frame. A spare in the tenth
frame gives the bowler one extra ball; a strike in the tenth gives him or her two
extra balls. A bowling score is computed as follows. A strike counts as 10 points
plus the sum of the next two balls. A spare counts as 10 points plus the next ball.
Any other balls merely count as themselves, as do any bonus balls rolled as a result
of a strike or a spare in the tenth frame. Write a program to accept from standard
input the scores for a sequence of balls and output the scores for the ten frames.
Example
INPUT
9 1 0 10 10 10 6 2 7 3 8 2 10 9 0 9 1 10
OUTPUT
Frame   Score
1           10
2           30
3           56
4           74
5           82
6           100
7           120
8           139
9           148
10         168
3. Igpay Atinlay Odecay (4 pts)
Write function that translated a text to Pig Latin. English is translated to Pig
Latin by taking the first letter of every word, moving it to the end of the word
and adding 'ay'.
Example
INPUT
The quick brown fox
OUTPUT
"The quick brown fox" becomes "Hetay uickqay rownbay oxfay".
4. Square Code (16 pts)
One classic method for composing secret messages is called a square code. The
spaces are removed from the English text and the characters are written into a
square (or rectangle). For example, the sentence "If man was meant to stay on the
ground god would have given us roots" is 54 characters long, so it is written into
a rectangle with 7 rows and 8 columns.
ifmanwas
meanttos
tayonthe
groundgo
dwouldha
vegivenu
sroots
The coded message is obtained by reading down the columns going left to right.
For example, the message above is coded as:
imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau
In your program, have the user enter a message in English. Have the maximum
message length be 81 characters. Display the encoded message.
(Watch out that no "garbage" characters are printed.)
Examples
INPUT                 OUTPUT
have a nice day     hae and via ecy
feed the dog          fto ehg ee dd
chill out                 clu hlt io
5. Card Value (4 pts)
A group of friends get together for simple card game. For each hand of playing
cards, they compute the total numerical value of that “hand.”
The suits are:          Card values are:
C = Clubs               2..10 = face value
D = Diamonds        J, Q, K = 10
H = Hearts              A = 11
S = Spades     
If only 2 suits are in the hand, add 10 points.
If all cards are of the same single suit, add 25 points.
Write a program to output the sum of the given hand. The maximum number of cards
in a hand is 10 and each card occurs only 1 time in a hand.
Examples
INPUT                                     OUTPUT
2C 10H AD KH 4S                 37 Points
9H QD QC 3H 3D AC AH     57 Points
7C 8C AC 4D                          40 Points
6. Where Does It Fit? (2 pts)
For an input word, determine whether it is alphabetically located before the word
EXERCISE, after the word MUSCLES, or between EXERCISE and MUSCLES. Ignore input case
Examples
INPUT      OUTPUT
rest             Rest is AFTER MUSCLES
aChE         Ache is BEFORE EXERCISE
GYM         Gym is BETWEEN EXERCISE and MUSCLES
7. Write a program that computes the following: (4 pts)
4 * ∑ [{(-1)^(k+1)}/(2k -1)], k = 1 to 10^6
8. Palindrome (16 pts)
A positive integer is said to be a palindrome with respect to base b, if its
representation in base b reads the same from left to right as from right to left.
Palindromes are formed as follows:
Given a number, reverse its digits and add the resulting number to the original number.
If the result isn't a palindrome, repeat the process. For example, start with 87 base 10.
Applying this process, we obtain:
87 + 78 = 165
165 + 561 = 726
726 + 627 = 1353
1353 + 3531 = 4884, a palindrome
Whether all numbers eventually become palindromes under this process is unproved, but all base
10 numbers less than 10,000 have been tested. Every one becomes a palindrome in a relatively
small number of steps (of the 900 3-digit numbers, 90 are palindromes to start with and 735 of
the remainder take fewer than 5 reversals and additions to yield a palindrome). Except, that is,
for 196. Although no proof exists that it will not produce a palindrome, this number has been
carried through to produce a 2 million-digit number without producing a palindrome.
Write a program that prints the palindrome produced given a positive, base 10 integer. If no
palindrome is produced after 10 additions, print the word “none” and the last sum.
+2 points for taking base, b as an argument
Examples
INPUT         OUTPUT
87                 4884
196               NONE, 18211171
1689             56265
1211, 3         112211 (extra points)
9. Rock, Paper, And Scissors Tournament (8 pts)
A tournament is being held for champion players of the game Rock, Paper, and Scissors.
R represents rock, P represents paper, and S represents scissors. The game is a draw
if both players choose the same item. Paper wins over rock because paper covers rock.
Scissors wins over paper because scissors cuts paper. Rock wins over scissors because
rock breaks scissors.
For Player A and Player B, write a program to determine who wins each game and who wins
the overall tournament. The first letter in the pair is the choice for player A and the
second letter is the choice for player B.
Example
INPUT
RRRSSRSPPPPSRP
OUTPUT
Game 1: DRAW
Game 2: A WINS
Game 3: B WINS
Game 4: A WINS
Game 5: DRAW
Game 6: B WINS
Game 7: B WINS
B WINS TOURNAMENT
10. Push Ups with Blaze (2 pts)
At UAB football games, Blaze does push ups after each Blazer score. After the first
Blazer touchdown (and point after), Blaze does 7 push ups. After the second touchdown
and point after, the score is now 14 and Blaze does 14 push ups.
Write a program that calculates how many total push ups Blaze does during the whole game.
Assume that only 7 point touchdowns (including the point after) occur. Prompt for the final
score and print out how many push ups Blaze has done.
Example
INPUT
Enter final score: 21
OUTPUT
Push ups: 42