Connection Status:
Competition Arena > Yllion
TCO19 SRM 748 · 2019-01-09 · by misof · Simple Math, String Manipulation, String Parsing
Class Name: Yllion
Return Type: String
Method Name: getPower
Arg Types: (string, string)
Problem Statement

Problem Statement

The -yllion notation is an alternate notation for powers of 10 designed by Donald Knuth. The main feature of this notation is that the grouping of digits is exponential, not linear. That is, each new name is used to double the number of digits. Equivalently, each new name represents a power of ten whose exponent is twice the previous one. Below we explain this in more detail.

Knuth's names for the powers of 10 are constructed as follows:

  • As usual, 10^0 is called "one" and 10^1 is called "ten".
  • The next two powers of ten are the hundreds: 10^2 is "one hundred" and 10^3 is "ten hundred".
  • The following four powers are the myriads. That is, 10^4 is "one myriad", and the others follow logically: 10^5 is "ten myriad", 10^6 is "one hundred myriad", and 10^7 is "ten hundred myriad".
  • The eight powers that follow are the myllions: 10^8 is "one myllion", 10^9 is "ten myllion", ..., and 10^15 is "ten hundred myriad myllion".
  • ...

The next names used after "myllion" are the following ones: "byllion", "tryllion", "quadryllion", "quintyllion", "sextyllion", "septyllion", "octyllion", "nonyllion", and "decyllion". Each is appended after all the previous ones, and the value of each is the square of the previous one. That is, "one byllion" is 10^16, "one tryllion" is 10^32, "one quadryllion" is 10^64, and so on.

You are given the Strings a and b that each describe a valid power of 10 in Knuth's notation. Return a String containing Knuth's name for their product.

Constraints

  • a and b will be valid powers of 10 in Knuth's notation.
  • a and b will each be strictly smaller than "one decyllion".
Examples
0)
"one"
"one"
Returns: "one"

One times one is one.

1)
"one"
"ten"
Returns: "ten"
2)
"one hundred"
"one hundred"
Returns: "one myriad"

Remember that you have to express the answer in Knuth's notation as well. Our 10,000 (ten thousand) is called "one myriad".

3)
"ten hundred"
"one hundred"
Returns: "ten myriad"
4)
"ten hundred myriad myllion"
"one hundred myllion tryllion"
Returns: "ten myllion byllion tryllion"
5)
"ten hundred myriad myllion byllion tryllion quadryllion quintyllion sextyllion septyllion octyllion nonyllion"
"ten"
Returns: "one decyllion"

This a is the largest possible number that can appear in the input.

Submissions are judged against all 60 archived test cases, of which 6 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class Yllion with a public method string getPower(string a, string b) · 60 test cases · 2 s / 256 MB per case

Submitting as anonymous