Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- string unitsPrint(int n) {
- return
- (n == 1 ? "one" :
- n == 2 ? "two" :
- n == 3 ? "three" :
- n == 4 ? "four" :
- n == 5 ? "five" :
- n == 6 ? "six" :
- n == 7 ? "seven" :
- n == 8 ? "eight" :
- n == 9 ? "nine" : "");
- }
- string tensPrint(int t, int u) {
- string result =
- t == 1 ? (
- u == 0 ? "ten" :
- u == 1 ? "eleven" :
- u == 2 ? "twelve" :
- u == 3 ? "thirteen" :
- u == 4 ? "fourteen" :
- u == 5 ? "fifteen" :
- u == 6 ? "sixteen" :
- u == 7 ? "seventeen" :
- u == 8 ? "eighteen" :
- "nineteen"
- ) :
- t == 2 ? "twenty" :
- t == 3 ? "thirty" :
- t == 4 ? "forty" :
- t == 5 ? "fifty" :
- t == 6 ? "sixty" :
- t == 7 ? "seventy" :
- t == 8 ? "eighty" :
- t == 9 ? "ninety" : "";
- return (t > 0 ? result + " " : "");
- }
- string hundredsPrint(int n) {
- return (n > 0 ? unitsPrint(n) + " hundred " : "");
- }
- string thousandsPrint(int n) {
- return (n > 0 ? unitsPrint(n) + " thousand " : "");
- }
- int main() {
- string n;
- cin >> n;
- n = "000" + n;
- int thousands = int(n[n.length() - 4]) - 48;
- int hundreds = int(n[n.length() - 3]) - 48;
- int tens = int(n[n.length() - 2]) - 48;
- int units = int(n[n.length() - 1]) - 48;
- cout << (thousands + hundreds + tens + units != 0
- ? thousandsPrint(thousands) + hundredsPrint(hundreds) + tensPrint(tens, units) + (tens != 1 ? unitsPrint(units) : "")
- : "zero") << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement