-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10101.cpp
52 lines (46 loc) · 1.22 KB
/
10101.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
47
48
49
50
51
52
#include <iomanip>
#include <iostream>
#include <string>
int width[] = {2, 2, 2, 1};
std::string unit[] = {" kuti", " lakh", " hajar", " shata"};
bool show(const std::string &s, int i)
{
bool printed;
if (i < 0) i = 3;
int digit;
if (s.size() > width[i]) {
printed = show(s.substr(0, s.size() - width[i]), i - 1);
digit = std::stoi(s.substr(s.size() - width[i]));
}
else {
digit = std::stoi(s);
}
if (digit)
std::cout << " " << digit << unit[i];
else if (i == 0 && printed)
std::cout << unit[i];
return printed || digit;
}
int main(void)
{
bool printed;
int idx = 0, digit;
std::string buffer;
while (std::cin >> buffer) {
std::cout << std::setw(4) << ++idx << ".";
if (buffer.size() > 2) {
printed = show(buffer.substr(0, buffer.size() - 2), 3);
digit = std::stoi(buffer.substr(buffer.size() - 2));
}
else {
printed = false;
digit = std::stoi(buffer);
}
if (digit)
std::cout << " " << digit;
else if (!printed)
std::cout << " " << digit;
std::cout << std::endl;
}
return 0;
}