Solved LeetCode program · 218 of 1,000
#0273 · Integer to English Words
Original English source
Keep a shared ones holding "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", and "Nineteen". Keep a shared tens holding "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", and "Ninety". Keep a shared part as empty text.
To render from value (a whole number). The hundreds is value divided by 100. If value is at least 100, Place item hundreds of ones into part, Place " Hundred" into part. Set value to value modulo 100. If value is 0, return. If value is more than 0 and hundreds is more than 0, Place " " into part. If value is less than 20, Place item value of ones into part, return. The tensdigit is value divided by 10. Place item (tensdigit minus 2) of tens into part. The digit is value modulo 10. If digit is more than 0, Place " " into part, Place item digit of ones into part.
The number is 123. The value is number. The billions is value divided by 1000000000. If value is at least 1000000000, render from billions, Place " Billion" into part, set value to value modulo 1000000000. The millions is value divided by 1000000. If value is at least 1000000 and the length of part is more than 0, Place " " into part. If value is at least 1000000, render from millions, Place " Million" into part, set value to value modulo 1000000. The thousands is value divided by 1000. If value is at least 1000 and the length of part is more than 0, Place " " into part. If value is at least 1000, render from thousands, Place " Thousand" into part, set value to value modulo 1000. If value is more than 0 and the length of part is more than 0, Place " " into part. If value is more than 0, render from value. If number is 0, Place "Zero" into part.
Show part.
Expected stdout
One Hundred Twenty Three