Problem Statement
The keycaps on a keyboard have been switched around, and the user is now trying to remember what he was trying to type.
Create a class CeyKaps containing the method decipher that takes a
A keycap can be switched around more than once. For example, if someone switched around 'A' and 'S', then switched around 'S' and 'D', then 'D' would be where 'A' originally was, 'S' where 'D' was, and 'A' where 'S' was.
The elements of switches will be formatted as (quotes added for clarity) "*:*", where the *'s represent the keycaps to be switched. The above example would be represented as: {"A:S","S:D","D:A"}, or alternately as {"S:A","D:S","A:D"} or any other such combination. The order of the keycaps doesn't matter, but the order of the switches does.
Definition
- Class:
- CeyKaps
- Method:
- decipher
- Parameters:
- String, String[]
- Returns:
- String
- Method signature:
- String decipher(String typed, String[] switches)
- (be sure your method is public)
Notes
- There is no restriction on how many times keycaps can be switched. It is perfectly possible to return to the original keyboard configuration.
Constraints
- typed will be between 1 and 50 characters in length, inclusive.
- each character of typed will be an uppercase letter ('A'-'Z').
- switches will contain between 1 and 50 elements, inclusive.
- each element of switched will be formatted as (quotes added for clarity) "*:*" where each * represents a single uppercase letter ('A'-'Z'), inclusive, but both *'s do not represent the same letter.
Examples
"AAAAA"
{"A:B"}
Returns: "BBBBB"
"AAAAA"
{"A:B","B:C","A:D"}
Returns: "CCCCC"
At first, all keys look right. After the A:B switch, A looks like B and B looks like A. After the B:C switch, A looks like C, B looks like A, and C looks like B. The third switch is irrelevant. Since "AAAAA" is what comes out, Timmy must have been pressing "CCCCC".
"ABCDE"
{"A:B","B:C","C:D","D:E","E:A"}
Returns: "AEBCD"
"HEWWO"
{"W:L"}
Returns: "HELLO"
"IHWSIOTCHEDMYKEYCAPSARWUND"
{"W:O","W:I"}
Returns: "WHOSWITCHEDMYKEYCAPSAROUND"
"WHUTSWETHTHATYPIS"
{"A:E","A:I","A:O","A:U"}
Returns: "WHATSWITHTHETYPOS"
"AGAMEMNON"
{"A:B","M:N"}
Returns: "BGBNENMOM"
"AGKKSLEKAMMSNEOWPPDOSIMED"
{"A:K","S:K","A:E","P:D","D:M","L:E","N:W"}
Returns: "SGLLKEALSDDKWAONMMPOKIDAP"
"LRUNPSTFDJOGY"
{"K:L","J:L","H:L","G:L","F:L","D:L","S:L","A:L", "O:P","I:P","U:P","Y:P","T:P","R:P","E:P","W:P","Q:P", "N:M","B:M","V:M","C:M","X:M","Z:M"}
Returns: "KEYBOARDSHIFT"
"ERJSBRNRRMDJOGYRFYPYJRTOHJYDOFR"
{"K:L","J:L","H:L","G:L","F:L","D:L","S:L","A:L", "O:P","I:P","U:P","Y:P","T:P","R:P","E:P","W:P","Q:P", "N:M","B:M","V:M","C:M","X:M","Z:M"}
Returns: "WEHAVEBEENSHIFTEDTOTHERIGHTSIDE"
"EVERYTHINGSHOULDBETHEPREVIOUSLETTER"
{"A:B","B:C","C:D","D:E","E:F","F:G","G:H","H:I","I:J", "J:K","K:L","L:M","M:N","N:O","O:P","P:Q","Q:R","R:S", "S:T","T:U","U:V","V:W","W:X","X:Y","Y:Z"}
Returns: "DUDQXSGHMFRGNTKCADSGDOQDUHNTRKDSSDQ"
"DUDQXSGHMFRGNTKCADSGDOQDUHNTRKDSSDQ"
{"Z:Y","Y:X","X:W","W:V","V:U","U:T","T:S","S:R","R:Q", "Q:P","P:O","O:N","N:M","M:L","L:K","K:J","J:I","I:H", "H:G","G:F","F:E","E:D","D:C","C:B","B:A"}
Returns: "EVERYTHINGSHOULDBETHEPREVIOUSLETTER"
"AGSGEMMZMZMXPOVQJEWYTMZ"
{"A:E"}
Returns: "EGSGAMMZMZMXPOVQJAWYTMZ"
"GKSKKEOGOSOKEKOGOKSKEO"
{"G:K","K:S","S:G","S:K"}
Returns: "GKSKKEOGOSOKEKOGOKSKEO"
"FINITO"
{"A:B"}
Returns: "FINITO"
"ABC"
{"A:B","B:C"}
Returns: "CAB"
"ASD"
{"A:S","S:D","D:A"}
Returns: "ADS"
"ABC"
{"A:B","A:B","B:C"}
Returns: "ACB"
"ABC"
{"A:B","B:C","A:B"}
Returns: "CBA"
"TESTESTEST"
{ "E:S", "E:S", "T:E" }
Returns: "ETSETSETSE"
"IHWSIOTCHEDMYKEYCAPSARWUND"
{ "W:O", "W:I" }
Returns: "WHOSWITCHEDMYKEYCAPSAROUND"
"ABCDE"
{ "A:B", "B:C", "C:D", "D:E", "E:A" }
Returns: "AEBCD"
"AC"
{ "A:C" }
Returns: "CA"
"QQQ"
{ "A:B", "B:Q", "A:R", "B:R" }
Returns: "RRR"
"ZZZZZZZZZZZZZZ"
{ "Z:A" }
Returns: "AAAAAAAAAAAAAA"