Statistics

Problem Statement for "CryptoDigit"

Problem Statement

Given a mapping from the digits '0','1',...,'9' to some 10 characters, we want to be able to calculate the sum of two numbers (in base 10) that are already mapped and express it under the mapping.

Create a class CryptoDigit that contains the method add that takes a String, mapping, representing the mapping of digits, and two Strings representing numbers under the mapping as inputs and returns a String which is the sum (under the mapping). mapping will be a String with exactly 10 characters, where character i represents the character that the ith digit maps to.

Definition

Class:
CryptoDigit
Method:
add
Parameters:
String, String, String
Returns:
String
Method signature:
String add(String mapping, String num1, String num2)
(be sure your method is public)

Notes

  • mapping will contain the 10 mapped characters corresponding to our '0','1',...,'9' in that order.
  • The returned String should not have superfluous leading mapped zeroes (see Example 0).
  • num1 and num2 may contain leading mapped zeroes.

Constraints

  • mapping contains exactly 10 characters, all distinct
  • mapping contains only lowercase letters a-z and digits 0-9
  • num1 and num2 contain only characters that appear in mapping
  • num1 contains between 1 and 9 characters, inclusive.
  • num2 contains between 1 and 9 characters, inclusive.

Examples

  1. "0123456789"

    "91"

    "0009"

    Returns: "100"

    This is the identity mapping.

  2. "9876543210"

    "91"

    "0009"

    Returns: "0001"

    num1 is what we call "8" and num2 is what we call "9990", so their sum is what we call "9998" which is 0001 under the mapping.

  3. "abcdefghij"

    "jjjjjjjjj"

    "jjjjjjjjj"

    Returns: "bjjjjjjjji"

  4. "abcdefghij"

    "a"

    "aaaab"

    Returns: "b"

  5. "abcdefghij"

    "j"

    "b"

    Returns: "ba"

  6. "ab7defg9i2"

    "aa"

    "aaa"

    Returns: "a"

    This leading mapped zero is necessary.

  7. "a8d7s6g5j4"

    "87654"

    "adsgj"

    Returns: "8gas5"

  8. "0123456789"

    "999999999"

    "1"

    Returns: "1000000000"

  9. "asdfghijkp"

    "ahfhhhshh"

    "ahfhhhshh"

    Returns: "sajssafsa"

  10. "1234567890"

    "0001"

    "1111"

    Returns: "0001"

  11. "1234567890"

    "0000"

    "2"

    Returns: "21111"

  12. "1234567890"

    "1234"

    "234"

    Returns: "357"

  13. "qwertyuiop"

    "ppprtpqep"

    "prtyrpewp"

    Returns: "wprroooeto"


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: