The Programming Olympiad is a prestigious event where thousands of programmers from South Africa compete to be placed among the top 15 programming students in the country. The first round was written on 1 August 2014 and the paper consisted of five thought-provoking programming problems.

Unfortunately, I was unable to solve the last question and I need your help.

**PROBLEM #5: Transformation**

Some doors can be unlocked using a key card - a plastic card with holes in it. A key card may be square like this :(O means a hole, X means no hole); but it may also be a rectangle or triangle.

```
XXXO
XXOX
XOXX
XXOX
```

However in order to work, these specific key cards have to be rotated or flipped according to one or more of these transformation instructions:

R = Rotate 90 degrees to the right

T = Top to bottom flip: you see the back - upside down

L = Left to right flip; you see the back - mirrored

**Task**

Write a program that will take the given key card, rotate, and/or flip it as instructed, and print out the resulting key card. No card will be more than 40 by 40 spaces.

Example:

Input:

```
XXXO
XXOX
XOXX
XXOX
```

Transformation: R, L

Output:

```
XXXX
XXOX
XOXO
OXXX
```

Explanation:

After rotating by 90 degrees:

```
XXXX
XOXX
OXOX
XXXO
```

After a left to right flip:

```
XXXX
XXOX
XOXO
OXXX
```

Credit: Allan Smithee

No vote yet

1 vote

×

Problem Loading...

Note Loading...

Set Loading...

Easy Math Editor

`*italics*`

or`_italics_`

italics`**bold**`

or`__bold__`

boldNote: you must add a full line of space before and after lists for them to show up correctlyparagraph 1

paragraph 2

`[example link](https://brilliant.org)`

`> This is a quote`

Remember to wrap math in \( ... \) or \[ ... \] to ensure proper formatting.`2 \times 3`

`2^{34}`

`a_{i-1}`

`\frac{2}{3}`

`\sqrt{2}`

`\sum_{i=1}^3`

`\sin \theta`

`\boxed{123}`

## Comments

Sort by:

TopNewestTest your program with:

a)

Transformation: T

b)

Transformation: T, L, R

c)

Transformation: R, T, L

Log in to reply

I think using a two-dimensional array and then creating methods for each transformation works for the first two cases. I'm clueless how to do the triangle case though...

Log in to reply

Hi Daniel. First off, I'm a big fan. Davis Sparinskis suggested that you can use a space 'character' to get the correct shape for the triangle. My initial thought was to also use a two dimensional array, however, I encountered some problems. Please HELP!

Log in to reply

Couldn't it be assumed that in the triangular case there is a third symbol - space? Then the triangular case would be the same as the others since the symbol itself doesn't matter as long as it's there. Unless that's against the rules or I've misunderstood the input.

Log in to reply

Log in to reply

This is my solution using a 2-D array and treating each of the cards as a square, with symbols ' o ' ,' x ' and ' '. The downside with this approach is that all of the symbols have to be entered manually.

Log in to reply

:/

Log in to reply