The Hardest Problem Ever
From Progteam
| Sorter: | Uncategorized |
|---|---|
| Source: | South Central USA 2002 |
| Link: | http://acm.pku.edu.cn/JudgeOnline/problem?id=1298 |
The Hardest Problem Ever is problem number 1298 on the Peking University ACM site.
Contents |
Problem Information
Problem Name: The Hardest Problem Ever
Problem Number on PKU: 1298
Synopsis: Simulating Caesar Cipher Scheme.
Solver Information
Solver: Eric Hong
Date: November 02, 2007
General Strategy
- Using Scanner, take the input.
- Decrypt the message using Caesar Cipher Scheme.
Solution
import java.util.*;
public class Main
{
public static Scanner in;
public static void main(String[] args)
{
in = new Scanner(System.in);
doStuff();
}
public static void doStuff()
{
String message = in.nextLine();
while (!message.equals("ENDOFINPUT"))
{
while (! ((message.equals("START")) || (message.equals("END"))))
{
solve(message);
message = in.nextLine();
}
message = in.nextLine();
}
}
public static void solve(String message)
{
Caesar cipher = new Caesar();
String newMessage = cipher.decrypt(message);
System.out.println(newMessage);
}
}
class Caesar
{
public static final int ALPHASIZE = 26;
public static final char[] alpha = {'A','B','C','D','E','F','G','H', 'I',
'J','K','L','M', 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
protected char[] encrypt = new char[ALPHASIZE];
protected char[] decrypt = new char[ALPHASIZE];
public Caesar()
{
for (int i=0; i<ALPHASIZE; i++)
encrypt[i] = alpha[(i + 5) % ALPHASIZE];
for (int i=0; i<ALPHASIZE; i++)
decrypt[encrypt[i] - 'A'] = alpha[i];
}
public String decrypt(String secret)
{
char[] mess = secret.toCharArray();
for (int i=0; i<mess.length; i++)
if (Character.isUpperCase(mess[i]))
mess[i] = decrypt[mess[i] - 'A'];
return new String(mess);
}
}
Additional Remarks
Memory: 2444K Time: 312MS