Problem Statement
Create a class CryptoDigit that
contains the method add that takes a
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
"0123456789"
"91"
"0009"
Returns: "100"
This is the identity mapping.
"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.
"abcdefghij"
"jjjjjjjjj"
"jjjjjjjjj"
Returns: "bjjjjjjjji"
"abcdefghij"
"a"
"aaaab"
Returns: "b"
"abcdefghij"
"j"
"b"
Returns: "ba"
"ab7defg9i2"
"aa"
"aaa"
Returns: "a"
This leading mapped zero is necessary.
"a8d7s6g5j4"
"87654"
"adsgj"
Returns: "8gas5"
"0123456789"
"999999999"
"1"
Returns: "1000000000"
"asdfghijkp"
"ahfhhhshh"
"ahfhhhshh"
Returns: "sajssafsa"
"1234567890"
"0001"
"1111"
Returns: "0001"
"1234567890"
"0000"
"2"
Returns: "21111"
"1234567890"
"1234"
"234"
Returns: "357"
"qwertyuiop"
"ppprtpqep"
"prtyrpewp"
Returns: "wprroooeto"