Connection Status:
Competition Arena > VideoCrypto
SRM 135 · 2003-02-11 · by axchma
Class Name: VideoCrypto
Return Type: String[]
Method Name: decoding
Arg Types: (vector<string>, vector<string>)
Problem Statement

Problem Statement

An interesting way of encrypting/decrypting black and white images works as follows. Suppose you possess a picture KEY which was your secret decryption key, and have been sent an encrypted image CYPHER. For example:

CYPHER:

X..XX.
.XX..X
.X.XX.
X..X.X

KEY:

.XX..X
.X.X.X
.XX.X.
X.X..X

To decrypt CYPHER you first overlay the two images, producing a JOINT image which has an 'X' wherever either KEY or CYPHER or both have an 'X'. The JOINT image corresponding to the KEY and CYPHER above is shown below:

XXXXXX
.XXX.X
.XXXX.
X.XX.X

Next you scan through the image one row at a time. If an even-numbered column, and the odd-numbered column that immediately follows it, are both 'X's, then both should be 'X's in the decrypted image. (The first column is column 0). Otherwise, if only the even-numbered column, or only the odd-numbered column is an 'X', then both should be '.' in the decrypted image. Here, column refers to the horizontal position and row refers to vertical position in the image. Below is the decrypted image corresponding to the images above:

XXXXXX
..XX..
..XX..
..XX..

Your task is, given a String[] key, each of whose elements represents a row of KEY, and a String[] cypher, each of whose elements represents a row of CYPHER, return a String[] representing the decrypted image.

Constraints

  • key has between 1 and 50 elements inclusive
  • cypher has the same number of elements as key
  • all elements of key have the same length
  • the length of the elements of key is an even number between 2 and 50 inclusive
  • all elements of cypher have the same length which is equal to the length of all elements of key
  • elements of key and cypher only contain the characters 'X' and '.'
  • for each element of key and cypher, every even-indexed (where indexing starts from 0) character is different than the character that immediately follows it
Examples
0)
{".XX..X"}
{"X.X.X."}
Returns: { "XX..XX" }
1)
{".XX..X",".X.X.X",".XX.X.","X.X..X"}
{".XX..X",".X.X.X",".XX.X.","X.X..X"}
Returns: { "......",  "......",  "......",  "......" }
2)
{"X..XX.",".XX..X",".X.XX.","X..X.X"}
{".XX..X",".X.X.X",".XX.X.","X.X..X"}
Returns: { "XXXXXX",  "..XX..",  "..XX..",  "..XX.." }
3)
{"X..XX.",".XX..X",".X.XX.","X..X.X"}
{".XX..X","X..XX.","X.X..X",".XX.X."}
Returns: { "XXXXXX",  "XXXXXX",  "XXXXXX",  "XXXXXX" }
4)
{"X..XX.",".XX..X",".X.XX.","X..X.X","X..XX.",".XX..X",".X.XX.","X..X.X"}
{".X.X.X",".XX..X",".XX.X.","X.X..X","X.X.X.",".XX..X","X..X.X","X.X..X"}
Returns: { "XX..XX",  "......",  "..XX..",  "..XX..",  "..XX..",  "......",  "XX..XX",  "..XX.." }
5)
{"X.X.X..XX.",".XX.X.X..X",".XX..X.X.X","X..X.XX..X",
"X.X..XX..X","X..XX.X.X.","X.X..X.XX."}
{"X.X..X.XX.",".XX..XX..X",".XX.X..X.X",".XX.X..XX.",
"X.X.X.X..X","X..X.XX.X.","X.X.X..XX."}
Returns: { "....XX....",  "....XX....",  "....XX....",  "XXXXXXXXXX",  "....XX....",  "....XX....",  "....XX...." }

picture for the secretKey is: X.X.X..XX. .XX.X.X..X .XX..X.X.X X..X.XX..X X.X..XX..X X..XX.X.X. X.X..X.XX. picture for the cypherText is: X.X..X.XX. .XX..XX..X .XX.X..X.X .XX.X..XX. X.X.X.X..X X..X.XX.X. X.X.X..XX. joint picture is: X.X.XX.XX. .XX.XXX..X .XX.XX.X.X XXXXXXXXXX X.X.XXX..X X..XXXX.X. X.X.XX.XX. decoded picture is: ....XX.... ....XX.... ....XX.... XXXXXXXXXX ....XX.... ....XX.... ....XX....

Submissions are judged against all 26 archived test cases, of which 6 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class VideoCrypto with a public method vector<string> decoding(vector<string> key, vector<string> cypher) · 26 test cases · 2 s / 256 MB per case

Submitting as anonymous