-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnumber-to-string.cpp
46 lines (39 loc) · 925 Bytes
/
number-to-string.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
const int N = 2e5 + 11;
void solve() {
string first[9] = {"one","two","three","four","five","six","seven","eight","nine"};
string second[9] = {"inv","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"};
int n;
cin>>n;
vector<string> v;
int cur;
bool _first = true;
while (n) {
cur = n%10;
v.push_back(_first?first[cur-1]:second[cur-1]);
_first = false;
n=n/10;
}
_first = false;
for (int i =v.size()-1; i >= 0; i--){
if(_first && v[i]!="inv") cout<<"-";
cout<<v[i];
_first = true;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
freopen("input.txt", "r", stdin);
int no_of_test_cases = 1;
// cin >> no_of_test_cases;
while (no_of_test_cases--) execute();
return 0;
}