CCC '19 S1 - Flipper


Submit solution

Points: 1
Time limit: 1.0s
Memory limit: 256M

Problem type
Allowed languages
Python

Problem Description

You are trying to pass the time while at the optometrist. You notice there is a grid of four numbers:

1 2
3 4

You see a random number of H (horizontal) and V (vertical) flips written on a piece of paper. You decide to figure out what the final arrangement of the grid will be, given the flips.

A horizontal flip swaps the top and bottom numbers in each column. A vertical flip swaps the left and right numbers in each row.

For example, if you are given the sequence HV, the grid starts as:

1 2
3 4

Performing the horizontal flip (H) results in:

3 4
1 2

Then, performing the vertical flip (V) results in:

4 3
2 1

Input Specification

The input consists of one line, containing a string of characters, each of which is either H or V, indicating a sequence of flips to perform. The number of flips will be between 1 and 1,000,000.

For test cases worth 2 marks, the string will contain exactly one character.

Output Specification

Output two lines, each containing two integers separated by a space, representing the final state of the grid.

Sample Input 1

HV

Sample Output 1

4 3
2 1

Sample Input 2

HHHH

Sample Output 2

1 2
3 4


Comments

There are no comments at the moment.