In: Computer Science
C++ code:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
//under twenty number
string und_twenty[20] =
{"Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"};
//under hundred numbers
string und_hundred[8] =
{"Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety"};
string convert(int n){
if(n>=20){
return " " + und_hundred[n/10-2] + convert(n%10);
}
else if(n>=1){
return " " + und_twenty[n];
}
return " ";
}
int main() {
int n;
cin>>n;
while(n!=-99){
// if n is valid then convert it to word form
if(n>=1&&n<=99){
string ans = convert(n);
cout<<ans.substr(1)<<'\n';
}
cin>>n;
}
cout<<"Have a nice day.\n";
return 0;
}