Your task is to decipher a non-empty string consisting of printable ASCII characters in the range [32..126].
Reading the string character per character:
- each time you encounter a letter in lowercase, associate it with the next letter in uppercase, starting with 'A'
- each time you encounter a letter in uppercase, replace it with the letter in lowercase it's associated with
- other characters do not require any special processing and are just left unchanged
Example
For the input string "endlAsEBAEE":
- Associate
etoA,ntoB,dtoCandltoD - Replace
Awithe - Associate
stoE - Replace
EBAEEwithsness
The final output is "endlessness".
Clarifications and rules
- The input string is guaranteed to contain each lowercase letter at most once. All further instances will be replaced with the corresponding capital letter.
- The input string is guaranteed to be valid. (You will not encounter a capital letter that is not yet associated with a lowercase letter.)
- Once a capital letter has been associated to a lowercase letter, it may or may not be used later in the string. For instance,
CandDare not used in the above example. - This is code-golf, so the shortest answer in bytes wins!
Test cases
Inputs:
abcd honk! ABCD! abrAcAdABCA endlAsEBAEE helCo wDrCd! dermatoglyphics progBamFinD AuzJles & cCdL DCKf sphinx of black quKrtz, jOdge my vGw. K NODLM IPGZE HGF SOWBA GYVP QCV JKRX TGU. petBr AiABD AEckBd a ABFG of AEFGlBH ABAABDs. hJw mIny AEFGLBH ABAABDM HEH ABCBD AEABD AEFG? Answers:
abcd honk! honk! abracadabra endlessness hello world! dermatoglyphics programming puzzles & code golf sphinx of black quartz, judge my vow. a quick brown fox jumps over the lazy dog. peter piper picked a peck of pickled peppers. how many pickled peppers did peter piper pick?