1..10 could be used
as shorthand for the list of integers from 1 to 10 inclusive.
Another common abbreviation is to give the first two and last
elements of a list where the difference between successive
elements is constant.
So, for example, 2,4..12 would be an abbreviation
for the list 2,4,6,8,10,12.
Note that we don't apply abbreviation blindly. For example,
there's no benefit in abbreviating 2,4,6 to
2,4..6. Also, there's no benefit in abbreviating
1,2 as 1..2.
Your task is to write a program that reads a list of up to 20 space-separated integers and prints the list in its most useful abbreviated form.
| Input | Output |
|---|---|
2 3 4 5 6 7 |
2 .. 7 |
4 7 10 13 16 19 |
4 7 .. 19 |
1 2 4 8 16 32 |
1 2 4 8 16 32 |
1 3 5 |
1 3 5 |
9 8 7 6 5 4 3 2 1 |
9 8 .. 1 |
1 2 3 4 5 4 |
1 2 3 4 5 4 |
Hyphenation can be described in terms of "rules": suffix strings that show where hyphenation may occur. The following rules describe the legal hyphenations for words ending in the letter 'c':
et-ic al-is-tic s-tic p-tic lyt-ic ot-ic an-tic n-tic c-tic at-ic h-nic n-ic m-ic l-lic b-lic -clic l-ic h-ic f-ic d-ic -bic a-ic i-acYour task is to write a program that reads a word from input and writes a version of the word on output hyphenated according to the first applicable rule.
| Input | Output |
|---|---|
ethnic |
eth-nic |
opportunistic |
opportunis-tic |
cardiac |
cardi-ac |
metallic |
metal-lic |
bucolic |
bucol-ic |
tic |
tic |
uninteresting |
uninteresting |
1, 2, 9, 4, 7, 3, 11, 8, 14A monotone increasing subsequence (MIS) is a subsequence of numbers which are strictly increasing from left to right. In the above example, the following are the MISs:
1, 2, 9 4, 7 3, 11 8, 14
Your task is to write a program that reads a sequence of up to 20 space-separated numbers from input and writes out the longest monotone increasing subsequence. If the sequence contains two equally long MISs, write out the one that occurs first in the sequence.
| Input | Output |
|---|---|
1 2 3 4 3 2 1 |
1 2 3 4 |
9 8 7 6 7 8 3 2 1 |
6 7 8 |
1 2 3 3 4 5 5 6 7 8 |
5 6 7 8 |
1 2 3 4 5 |
1 2 3 4 5 |
5 4 3 2 1 |
5 |
8 8 8 8 8 8 |
8 |
Your program should first read in the image. The user may enter up to 16 lines making up the image. No line may contain more than 16 characters. They then enter a line containing only a full stop ('.')
Any parts of the image not entered by the user are assumed to be spaces.
Your program should then print the image, exactly as in the example below.
The program should then read a command from the user. There are 4 possible commands:
| h n | Translate image n squares horizontally, n may be any integer |
| v n | Translate image n squares vertically, n may be any integer |
| r | Rotate image 90 degrees clockwise |
| . | Exit program |
Translations to areas outside the 16x16 image are ignored.
Translations from areas outside the 16x16 image are assumed to be spaces.
Enter image: abc def ghi . ################## #abc # #def # #ghi # # # # # # # # # # # # # # # # # # # # # # # # # # # ################## Enter command: h 1 ################## # abc # # def # # ghi # # # # # # # # # # # # # # # # # # # # # # # # # # # ################## Enter command: v 2 ################## # # # # # abc # # def # # ghi # # # # # # # # # # # # # # # # # # # # # # # ################## Enter command: r ################## # # # gda # # heb # # ifc # # # # # # # # # # # # # # # # # # # # # # # # # ################## Enter command: h -8 ################## # # # gda # # heb # # ifc # # # # # # # # # # # # # # # # # # # # # # # # # ################## Enter command: v -2 ################## # heb # # ifc # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ################## Enter command: h 42 ################## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ################## Enter command: .
Enter image: abcdefghijklmnop abcdefghijklmnop abcdefghijklmnop abcdefghijklmnop abcdefghijklmnop abcdefghijklmnop abcdefghijklmnop abcdefghijklmnop abcdefghijklmnop abcdefghijklmnop abcdefghijklmnop abcdefghijklmnop abcdefghijklmnop abcdefghijklmnop abcdefghijklmnop abcdefghijklmnop ################## #abcdefghijklmnop# #abcdefghijklmnop# #abcdefghijklmnop# #abcdefghijklmnop# #abcdefghijklmnop# #abcdefghijklmnop# #abcdefghijklmnop# #abcdefghijklmnop# #abcdefghijklmnop# #abcdefghijklmnop# #abcdefghijklmnop# #abcdefghijklmnop# #abcdefghijklmnop# #abcdefghijklmnop# #abcdefghijklmnop# #abcdefghijklmnop# ################## Enter command: r ################## #aaaaaaaaaaaaaaaa# #bbbbbbbbbbbbbbbb# #cccccccccccccccc# #dddddddddddddddd# #eeeeeeeeeeeeeeee# #ffffffffffffffff# #gggggggggggggggg# #hhhhhhhhhhhhhhhh# #iiiiiiiiiiiiiiii# #jjjjjjjjjjjjjjjj# #kkkkkkkkkkkkkkkk# #llllllllllllllll# #mmmmmmmmmmmmmmmm# #nnnnnnnnnnnnnnnn# #oooooooooooooooo# #pppppppppppppppp# ################## Enter command: r ################## #ponmlkjihgfedcba# #ponmlkjihgfedcba# #ponmlkjihgfedcba# #ponmlkjihgfedcba# #ponmlkjihgfedcba# #ponmlkjihgfedcba# #ponmlkjihgfedcba# #ponmlkjihgfedcba# #ponmlkjihgfedcba# #ponmlkjihgfedcba# #ponmlkjihgfedcba# #ponmlkjihgfedcba# #ponmlkjihgfedcba# #ponmlkjihgfedcba# #ponmlkjihgfedcba# #ponmlkjihgfedcba# ################## Enter command: v 3 ################## # # # # # # #ponmlkjihgfedcba# #ponmlkjihgfedcba# #ponmlkjihgfedcba# #ponmlkjihgfedcba# #ponmlkjihgfedcba# #ponmlkjihgfedcba# #ponmlkjihgfedcba# #ponmlkjihgfedcba# #ponmlkjihgfedcba# #ponmlkjihgfedcba# #ponmlkjihgfedcba# #ponmlkjihgfedcba# #ponmlkjihgfedcba# ################## Enter command: h -2 ################## # # # # # # #nmlkjihgfedcba # #nmlkjihgfedcba # #nmlkjihgfedcba # #nmlkjihgfedcba # #nmlkjihgfedcba # #nmlkjihgfedcba # #nmlkjihgfedcba # #nmlkjihgfedcba # #nmlkjihgfedcba # #nmlkjihgfedcba # #nmlkjihgfedcba # #nmlkjihgfedcba # #nmlkjihgfedcba # ################## Enter command: r ################## #nnnnnnnnnnnnn # #mmmmmmmmmmmmm # #lllllllllllll # #kkkkkkkkkkkkk # #jjjjjjjjjjjjj # #iiiiiiiiiiiii # #hhhhhhhhhhhhh # #ggggggggggggg # #fffffffffffff # #eeeeeeeeeeeee # #ddddddddddddd # #ccccccccccccc # #bbbbbbbbbbbbb # #aaaaaaaaaaaaa # # # # # ################## Enter command: h 1 ################## # nnnnnnnnnnnnn # # mmmmmmmmmmmmm # # lllllllllllll # # kkkkkkkkkkkkk # # jjjjjjjjjjjjj # # iiiiiiiiiiiii # # hhhhhhhhhhhhh # # ggggggggggggg # # fffffffffffff # # eeeeeeeeeeeee # # ddddddddddddd # # ccccccccccccc # # bbbbbbbbbbbbb # # aaaaaaaaaaaaa # # # # # ################## Enter command: v 1 ################## # # # nnnnnnnnnnnnn # # mmmmmmmmmmmmm # # lllllllllllll # # kkkkkkkkkkkkk # # jjjjjjjjjjjjj # # iiiiiiiiiiiii # # hhhhhhhhhhhhh # # ggggggggggggg # # fffffffffffff # # eeeeeeeeeeeee # # ddddddddddddd # # ccccccccccccc # # bbbbbbbbbbbbb # # aaaaaaaaaaaaa # # # ################## Enter command: .
For example:
Your program should read in the initial value in the sequence and then print the integers in the sequence until a value in the sequence occurs twice.
Your program should print both the initial value and the recurring value which caused printing of the sequence to halt.
| Input | Output |
|---|---|
| 7 | 7 1 1 |
| 14 | 14 17 29 73 85 161 53 61 25 41 17 |
| 153 | 153 93 109 37 85 161 53 61 25 41 17 29 73 85 |
| 349 | 349 301 13 13 |
A chessboard is an 8x8 square matrix. We label each square as below:
| a8 | b8 | c8 | d8 | e8 | f8 | g8 | h8 |
| a7 | b7 | c7 | d7 | e7 | f7 | g7 | h7 |
| a6 | b6 | c6 | d6 | e6 | f6 | g6 | h6 |
| a5 | b5 | c5 | d5 | e5 | f5 | g5 | h5 |
| a4 | b4 | c4 | d4 | e4 | f4 | g4 | h4 |
| a3 | b3 | c3 | d3 | e3 | f3 | g3 | h3 |
| a2 | b2 | c2 | d2 | e2 | f2 | g2 | h2 |
| a1 | b1 | c1 | d1 | e1 | f1 | g1 | h1 |
A knight makes an L-shaped move. It moves either two squares horizontally and one square vertically or two squares vertically and one square horizontally.
For example, a knight at d4 can move to one of eight squares: c2, e2, b3, b5, c6, e6, f3 or f5.
A move can not take a knight off the chessboard. Hence, a knight on square near the edge of the board will have fewer possible moves.
For example, a knight at a1 can move only to c2 and b3.
Your program should read in the label of a starting square and the label of a finishing square.
It should print a sequence of moves which take a knight from the starting square to the finishing square. This sequence of move should be as short as possible.
If there are multiple shortest sequences, you program may print any of them.
| Input | Output |
|---|---|
| d4 a1 | d4 c2 a1 |
| d4 b3 | d4 b3 |
| a1 h8 | a1 b3 c5 b7 d8 f7 h8 |
| g2 b2 | g2 f4 d3 b2 |
You can assume starting and finishing squares are different. No error checking is required.
This task is worth 30 points.