Problem Statement
Programmers often use hexadecimal integers - that is, numbers written in base 16. In this problem, a hexadecimal literal always begins with the characters "0x" (zero followed by a lowercase x). A hexadecimal literal must have at least one valid digit (0-9, A-F). Hence, the string "0x" itself is not a valid hexadecimal literal.
The strings DEADBEEF and BABACECA ("Grandma Ceca", in Bulgarian) are famous for consisting only of the first 6 letters of the English alphabet, thus being valid hexadecimal integers. Thus, 0xDEADBEEF = 3735928559 and 0xBABACECA = 3132804810 are valid hexadecimal literals. Because of that, these patterns are sometimes used as code constants.
Elly has noticed that the standard suffixes for type hinting in C++ (L, LL, U, UL, ULL, LU, LLU) can be added to the end of hexadecimal literals as well. More precisely, a hexadecimal literal either has no type hinting suffix at all, or it ends in exactly one of the seven suffixes we just mentioned. This way, for example, 0xFLU and 0xFULL are valid hexadecimal literals (with the value of 15), as is 0xFALL (which equals 250).
Additionally, the girl can use 0 as a 'O', 1 as 'I', 2 as 'Z', 5 as 'S', and 7 as 'T'. With these additions, for example the word TASTEFUL can be expressed as 0x7A57EFUL, OFFICIAL would be 0x0FF1C1AL, and OOZE would be 0x002E.
Now the girl wants to check whether some strings can be converted to such hexadecimal literals. Help her by writing a method, which, given a
Definition
- Class:
- EllysCodeConstants
- Method:
- getLiteral
- Parameters:
- String
- Returns:
- String
- Method signature:
- String getLiteral(String candidate)
- (be sure your method is public)
Constraints
- candidate will consist of between 1 and 8 characters, inclusive.
- candidate will consist only of uppercase letters from the English alphabet.
Examples
"DEADBEEF"
Returns: "0xDEADBEEF"
One of the examples from the problem statement.
"BABACECA"
Returns: "0xBABACECA"
Another example from the problem statement.
"TOPCODER"
Returns: ""
TopCoder unfortunately cannot be expressed as a hexadecimal literal, as the letters 'P' and 'R' are neither one of the first 6 letters of the alphabet, nor can be represented with digits. 'R' is also not one of the valid suffixes.
"FLU"
Returns: "0xFLU"
Note that the standard allows the suffix 'L' (or "LL") to be before 'U'.
"FULL"
Returns: "0xFULL"
"FALL"
Returns: "0xFALL"
"TASTEFUL"
Returns: "0x7A57EFUL"
"OFFICIAL"
Returns: "0x0FF1C1AL"
"OOZE"
Returns: "0x002E"
Leading zeroes are okay for such literals.
"ESPRIT"
Returns: ""
espr1t cannot be expressed in hex either, again because of 'P' and 'R' (as was the case in TopCoder).
"COOL"
Returns: "0xC00L"
"DISEASE"
Returns: "0xD15EA5E"
"SOLVED"
Returns: ""
Let's hope this problem will be ^^ by you!
"TASK"
Returns: ""
"DEAD"
Returns: "0xDEAD"
"ZEAL"
Returns: "0x2EAL"
"ZOOM"
Returns: ""
"SOUL"
Returns: "0x50UL"
"BADFOOD"
Returns: "0xBADF00D"
"ZESTFUL"
Returns: "0x2E57FUL"
"LUL"
Returns: ""
"LEET"
Returns: ""
"ZCELLOS"
Returns: ""
"UL"
Returns: ""
"ULT"
Returns: ""
"ALT"
Returns: ""
"YOU"
Returns: ""
"KNOW"
Returns: ""
"NOTHING"
Returns: ""
"JON"
Returns: ""
"SNOW"
Returns: ""
"SEIZE"
Returns: "0x5E12E"
"TISSUE"
Returns: ""
"BULL"
Returns: "0xBULL"
"TULL"
Returns: "0x7ULL"
"SULL"
Returns: "0x5ULL"
"ZULL"
Returns: "0x2ULL"
"OULL"
Returns: "0x0ULL"
"OUL"
Returns: "0x0UL"
"OWL"
Returns: ""
"TOOL"
Returns: "0x700L"
"TITS"
Returns: "0x7175"
"BILBO"
Returns: ""
"DOODLE"
Returns: ""
"FOSIL"
Returns: "0xF051L"
"STULL"
Returns: "0x57ULL"
"FOE"
Returns: "0xF0E"
"ORACUL"
Returns: ""
"ORACLE"
Returns: ""
"LIE"
Returns: ""
"BEOULF"
Returns: ""
"ADELU"
Returns: "0xADELU"
"DULL"
Returns: "0xDULL"
"BEZZOS"
Returns: "0xBE2205"
"LIBE"
Returns: ""
"LUBE"
Returns: ""
"OOL"
Returns: "0x00L"
"TOAST"
Returns: "0x70A57"
"BACKFILL"
Returns: ""
"BACFILL"
Returns: "0xBACF1LL"
"REFILL"
Returns: ""
"SEASON"
Returns: ""
"QWERTY"
Returns: ""
"UIOP"
Returns: ""
"ASDFGH"
Returns: ""
"JKL"
Returns: ""
"ZXCVBNM"
Returns: ""
"SOLO"
Returns: ""
"ABCDEF"
Returns: "0xABCDEF"
"DEFAUL"
Returns: "0xDEFAUL"
"DEFAULT"
Returns: ""
"TAPAS"
Returns: ""
"BOTTLE"
Returns: ""
"BLOAT"
Returns: ""
"FLOAT"
Returns: ""
"FOOL"
Returns: "0xF00L"
"COBALT"
Returns: ""
"ASTEA"
Returns: "0xA57EA"
"EAST"
Returns: "0xEA57"
"BEAST"
Returns: "0xBEA57"
"CUTE"
Returns: ""
"CAT"
Returns: "0xCA7"
"TODO"
Returns: "0x70D0"
"ZOO"
Returns: "0x200"
"BOZA"
Returns: "0xB02A"
"DOLU"
Returns: "0xD0LU"
"DOLL"
Returns: "0xD0LL"
"BESIDES"
Returns: "0xBE51DE5"
"IDEAS"
Returns: "0x1DEA5"
"SOLD"
Returns: ""
"USTA"
Returns: ""
"DEADBULL"
Returns: "0xDEADBULL"
"BLUEFALL"
Returns: ""
"CALL"
Returns: "0xCALL"
"CALLDOLL"
Returns: ""
"DESACITO"
Returns: "0xDE5AC170"
"LOGO"
Returns: ""
"DU"
Returns: "0xDU"
"DLL"
Returns: "0xDLL"
"L"
Returns: ""
"D"
Returns: "0xD"
"O"
Returns: "0x0"
"I"
Returns: "0x1"
"Z"
Returns: "0x2"
"S"
Returns: "0x5"
"T"
Returns: "0x7"
"LU"
Returns: ""
"DOLU"
Returns: "0xD0LU"
"HALLU"
Returns: ""
"ALU"
Returns: "0xALU"
"ILU"
Returns: "0x1LU"
"YOLO"
Returns: ""
"IOLU"
Returns: "0x10LU"
"LULU"
Returns: ""
"LULL"
Returns: ""
"BLUE"
Returns: ""
"CLUE"
Returns: ""
"DEAL"
Returns: "0xDEAL"
"LEAD"
Returns: ""
"SOLU"
Returns: "0x50LU"
"SOLO"
Returns: ""
"CLIO"
Returns: ""
"CELDO"
Returns: ""
"CELLO"
Returns: ""
"LOU"
Returns: ""
"CLOSE"
Returns: ""
"LUISE"
Returns: ""
"LITER"
Returns: ""
"LITTLE"
Returns: ""
"LISTOU"
Returns: ""
"ISLLU"
Returns: "0x15LLU"
"TOSCALLU"
Returns: "0x705CALLU"
"IELLU"
Returns: "0x1ELLU"
"LLUL"
Returns: ""
"ELLUL"
Returns: ""
"EAU"
Returns: "0xEAU"
"BLU"
Returns: "0xBLU"
"SLOU"
Returns: ""
"TL"
Returns: "0x7L"
"TLE"
Returns: ""
"WA"
Returns: ""
"RE"
Returns: ""
"XX"
Returns: ""
"IIIIIIII"
Returns: "0x11111111"
"IOISOTZ"
Returns: "0x1015072"
"OOOOOOOO"
Returns: "0x00000000"
"BOL"
Returns: "0xB0L"
"BUL"
Returns: "0xBUL"
"BULGARIA"
Returns: ""
"GLOBUS"
Returns: ""
"BLOBUS"
Returns: ""
"BLOB"
Returns: ""
"LLAMA"
Returns: ""
"LOCAL"
Returns: ""
"LAST"
Returns: ""
"TEST"
Returns: "0x7E57"
"ULL"
Returns: ""
"LLU"
Returns: ""
"LL"
Returns: ""
"U"
Returns: ""
"ULLA"
Returns: ""
"AULL"
Returns: "0xAULL"
"AA"
Returns: "0xAA"
"LFULL"
Returns: ""
"LLLLLL"
Returns: ""
"ZZZ"
Returns: "0x222"
"AAALLLLL"
Returns: ""
"ALLU"
Returns: "0xALLU"
"A"
Returns: "0xA"
"OLLL"
Returns: ""
"ABCZULL"
Returns: "0xABC2ULL"
"OLLU"
Returns: "0x0LLU"
"ULLU"
Returns: ""
"FLAL"
Returns: ""
"AL"
Returns: "0xAL"
"UU"
Returns: ""
"FULU"
Returns: ""
"OXA"
Returns: ""
"FL"
Returns: "0xFL"
"ZZZULL"
Returns: "0x222ULL"