DIXIE001 - Evil Overlord Cypher

You have been imprisoned by an evil, but stupid alien overlord. You told them it was a trap. It's not your fault. IT'S NOT YOUR FAULT.

You can pass notes containing information to other prisoners to coordinate your escape. You want to use an algorithm that can be easily deciphered by your fellow prisoners, in between torture sessions of forced “Buffy the Vampire Slayer” marathons. But you also want the notes to remain unreadable to evil alien overlord and his minions should the notes be discovered.

Therefore, you choose to implement a simple Caesar cypher given the following rule:

When the characters in the document are sorted by frequency, then by ASCII code (case sensitive), each character is replaced by the character in the same position in the reversely sorted set. Make a single character frequency lookup for ENTIRE file.

Given an arbitrary body of text as input, produce the appropriate output based on the cypher.

The first line of the input will contain a count of all the remaining lines, the remaining line are all part of the text to be encrypted.

Note: The symbol in the examples below represents a newline character. You may also ignore (strip/pop off) the first line of the input. It was added for languages that have difficulty (or lack of ability) detecting EOF.

Also note that the newlines in the input text are treated as any other character and are encoded with the rest of the text. Note in particular that the last line of output may not end with a newline character. THIS IS WHITESPACE SENSITIVE.

The sample input contains no whitespace characters at the end of a line unless marked with ¶ symbol at which point there is a newline character.

Examples

Input 1:
1
Aliens are dumb

Output 1:
 mn
ibAud
Aralse
Input 2:
1
Mississippi

Output 2:
spMMpMMpiip
Input 3:
2
Missi
ssippi

Output 3:
iM

Ms

MppM

Added by:Dixie State University
Date:2013-03-30
Time limit:1s-1.003s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Created by Daniel Evans for the DSU 2013 ACM Competition

hide comments
2013-04-01 18:49:26 mehmetin
I think each input file is missing a newline at the end. I treated each input file as ending with a newline and got AC. This time, however, I can't get correct result for sample inputs.

edit(author) - The last line of a file MAY OR MAY NOT end with a newline character. re is only a newline at the end of a line if it is marked with a newline character (as in the examples above). If there is no newline there may still be a space or other whitespace character. You should read each line AS IS. If you have difficulty detecting EOF use the line count from the first line of the input.

(Mehmet Inal): Yes, no mistake in input files. It was my mistake in the program.


Last edit: 2013-04-03 20:36:41
2013-04-01 18:49:26 mehmetin
I'm getting correct outputs for the sample inputs, but I think there is a problem in the second sample input. Mississippi ends with a space, that should produce a different output. Aren't we taking the last space into account?
--ans(francky)--> I think sample is badly formatted, try without a space and it should work. This spurious 'space' is really boring. I've edit the body to remove it.


Last edit: 2013-04-01 17:49:56
2013-04-01 18:49:26 joud zouzou
not clear, please clarify

Last edit: 2013-04-03 11:18:07
2013-04-18 16:30:41 Dixie State University
You will read the entire input (a single file) and have a single output. The largest file you will read is 593 lines to be encrypted at 25000+ bytes of data (easily doable in the given time limit)

Example of Input (without line count): "Mississippi"

Create a Character Frequency Lookup and resolve any ties using the ASCII value of the character.
  Hint: (freqency*256)+(ASCII Code)

Example Character Frequency: [(333, 'M'), (624, 'p'), (1129, 'i'), (1139, 's')]
Reverse Character Frequency: [(1139, 's'), (1129, 'i'), (624, 'p'), (333, 'M')]

So replace all instances of ("M" with "s"), ("p" with "i"), and vice versa.

So "Mississippi" -> "spMMpMMpiip"

Last edit: 2013-03-30 18:24:16
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.