Statistics

Problem Statement for "Hexspeak"

Problem Statement

If you compile a Java program and open the .class file in a text editor, you will find that the first four bytes spell "CAFEBABE" in hexadecimal. Using hexadecimal numbers to spell words is called Hexspeak.

Hexadecimal numbers are integers written in base 16. The letters 'A' through 'F' represent the digits with values 10 through 15. For example, the integer 202 written in hexadecimal is "CA". This is because 202 = 12*16 + 10, and the digits 12 and 10 are written as 'C' and 'A', respectively.

In this problem we will use eight different letters: in addition to the letters 'A' through 'F' we will also interpret the digit 0 as the letter 'O' and the digit 1 as the letter 'I'. Hence, any word that only consists of the letters ABCDEFIO can be interpreted as a hexadecimal number. Such words are called valid hexspeak words.

Fox Ciel has a long ciphertext containing a positive integer. Convert this number to hexadecimal. If you get the representation of a valid hexspeak word, return that word. Otherwise, return the string "Error!" (quotes for clarity). In other words, you should return "Error!" if the hexadecimal representation of ciphertext contains some occurrence of a digit between 2 and 9, inclusive.

Definition

Class:
Hexspeak
Method:
decode
Parameters:
long
Returns:
String
Method signature:
String decode(long ciphertext)
(be sure your method is public)

Notes

  • The correct hexadecimal representation of ciphertext does not contain any leading zeros.
  • The return value is case-sensitive.

Constraints

  • ciphertext will be between 1 and 1,000,000,000,000,000,000, inclusive.

Examples

  1. 257

    Returns: "IOI"

    The number 257 in decimal is written as 101 in hexadecimal. The digits 1 and 0 represent the characters 'I' and 'O', thus we should return "IOI".

  2. 258

    Returns: "Error!"

    The number 258 in decimal is written as 102 in hexadecimal. The digit 2 does not represent a letter, so we return "Error!".

  3. 3405691582

    Returns: "CAFEBABE"

  4. 2882400001

    Returns: "ABCDEFOI"

  5. 999994830345994239

    Returns: "DEOBIFFFFFFFFFF"

  6. 1000000000000000000

    Returns: "Error!"

  7. 1

    Returns: "I"

  8. 6264353636

    Returns: "Error!"

  9. 666060670776067

    Returns: "Error!"

  10. 563452344324234

    Returns: "Error!"

  11. 1

    Returns: "I"

  12. 2

    Returns: "Error!"

  13. 11

    Returns: "B"

  14. 10

    Returns: "A"

  15. 9

    Returns: "Error!"

  16. 4234197547616960

    Returns: "FOAFAFOBCOACO"

  17. 4207849484

    Returns: "FACEBOOC"

  18. 48358647426436591

    Returns: "ABCDEFOIABCDEF"

  19. 3022415463623629

    Returns: "Error!"

  20. 262

    Returns: "Error!"


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: