Impl reverse printing, refactorings and fixes
This commit is contained in:
parent
f4b935d8c6
commit
91eb8544a1
2 changed files with 50 additions and 30 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,3 +4,4 @@ src/*.o
|
||||||
compile_commands.commands.json
|
compile_commands.commands.json
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
.clangd/
|
.clangd/
|
||||||
|
.cache/
|
||||||
|
|
105
src/main.cpp
105
src/main.cpp
|
@ -36,20 +36,21 @@ const char8_t* ilgop = u8"일곱";
|
||||||
const char8_t* yudul = u8"여덟";
|
const char8_t* yudul = u8"여덟";
|
||||||
const char8_t* ahop = u8"아홉";
|
const char8_t* ahop = u8"아홉";
|
||||||
|
|
||||||
const char8_t* yul = u8"열";
|
const char8_t* yul = u8"열"; // 10
|
||||||
const char8_t* sumul = u8"스물";
|
const char8_t* sumul = u8"스물"; // 20
|
||||||
const char8_t* suhlun = u8"서른";
|
const char8_t* suhlun = u8"서른"; // 30
|
||||||
const char8_t* mahun = u8"마흔";
|
const char8_t* mahun = u8"마흔"; // 40
|
||||||
const char8_t* shin = u8"쉰";
|
const char8_t* shin = u8"쉰"; // 50
|
||||||
const char8_t* yesun = u8"예순";
|
const char8_t* yesun = u8"예순"; // 60
|
||||||
const char8_t* ilhun = u8"일흔";
|
const char8_t* ilhun = u8"일흔"; // 70
|
||||||
const char8_t* yuhdun = u8"여든";
|
const char8_t* yuhdun = u8"여든"; // 80
|
||||||
const char8_t* ahun = u8"아흔";
|
const char8_t* ahun = u8"아흔"; // 90
|
||||||
|
|
||||||
void help() {
|
void help() {
|
||||||
puts("Usage:");
|
puts("Usage:");
|
||||||
puts(" --max <integer> - set maximum value for generated value (default 999,999,999,999)");
|
puts(" --max <integer> - set maximum value for generated value (default 999,999,999,999)");
|
||||||
puts(" [-a | --alt] - use alternate Korean Numbers (up to 99)");
|
puts(" [-a | --alt] - use alternate Korean Numbers (up to 99)");
|
||||||
|
puts(" [-r | --reverse] - display Korean form first");
|
||||||
}
|
}
|
||||||
|
|
||||||
const char8_t* digit_to_kword(int n) {
|
const char8_t* digit_to_kword(int n) {
|
||||||
|
@ -238,39 +239,7 @@ std::u8string value_to_korean_alt(unsigned long long value) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
void printValue(unsigned long long value) {
|
||||||
unsigned long long max = 9999999999999;
|
|
||||||
bool isAlt = false;
|
|
||||||
|
|
||||||
--argc; ++argv;
|
|
||||||
while(argc > 0) {
|
|
||||||
if(std::strcmp(argv[0], "--help") == 0 || std::strcmp(argv[0], "-h") == 0) {
|
|
||||||
help();
|
|
||||||
return 0;
|
|
||||||
} else if(std::strcmp(argv[0], "--max") == 0 && argc > 1) {
|
|
||||||
--argc; ++argv;
|
|
||||||
max = std::strtoull(argv[0], nullptr, 0);
|
|
||||||
} else if(std::strcmp(argv[0], "-a") == 0 || std::strcmp(argv[0], "--alt") == 0) {
|
|
||||||
isAlt = true;
|
|
||||||
}
|
|
||||||
--argc; ++argv;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isAlt) {
|
|
||||||
printf("Using alternate Korean numbers, ");
|
|
||||||
if(max > 99) { max = 99; }
|
|
||||||
}
|
|
||||||
printf("Maximum value is set to %llu\n", max);
|
|
||||||
|
|
||||||
unsigned long long value;
|
|
||||||
{
|
|
||||||
std::default_random_engine r_eng(std::chrono::steady_clock::now().time_since_epoch().count());
|
|
||||||
std::uniform_int_distribution<unsigned long long> r_dist(0, max);
|
|
||||||
value = r_dist(r_eng);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("\nGot value \"");
|
|
||||||
{
|
|
||||||
std::string s;
|
std::string s;
|
||||||
unsigned long long temp = value;
|
unsigned long long temp = value;
|
||||||
unsigned char count = 0;
|
unsigned char count = 0;
|
||||||
|
@ -286,14 +255,64 @@ int main(int argc, char **argv) {
|
||||||
std::reverse(s.begin(), s.end());
|
std::reverse(s.begin(), s.end());
|
||||||
std::cout << s;
|
std::cout << s;
|
||||||
}
|
}
|
||||||
printf("\", hit enter to continue...");
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
unsigned long long max = 9999999999999;
|
||||||
|
bool isAlt = false;
|
||||||
|
bool reverse = false;
|
||||||
|
|
||||||
|
--argc; ++argv;
|
||||||
|
while(argc > 0) {
|
||||||
|
if(std::strcmp(argv[0], "--help") == 0 || std::strcmp(argv[0], "-h") == 0) {
|
||||||
|
help();
|
||||||
|
return 0;
|
||||||
|
} else if(std::strcmp(argv[0], "--max") == 0 && argc > 1) {
|
||||||
|
--argc; ++argv;
|
||||||
|
max = std::strtoull(argv[0], nullptr, 0);
|
||||||
|
} else if(std::strcmp(argv[0], "-a") == 0 || std::strcmp(argv[0], "--alt") == 0) {
|
||||||
|
isAlt = true;
|
||||||
|
} else if(std::strcmp(argv[0], "-r") == 0 || std::strcmp(argv[0], "--reverse") == 0) {
|
||||||
|
reverse = true;
|
||||||
|
}
|
||||||
|
--argc; ++argv;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isAlt) {
|
||||||
|
printf("Using alternate Korean numbers, ");
|
||||||
|
if(max > 99) { max = 99; }
|
||||||
|
}
|
||||||
|
printf("Maximum value is set to %llu\n", max);
|
||||||
|
|
||||||
|
unsigned long long value;
|
||||||
|
{
|
||||||
|
std::default_random_engine r_eng(std::chrono::steady_clock::now().time_since_epoch().count());
|
||||||
|
std::uniform_int_distribution<unsigned long long> r_dist(1, max);
|
||||||
|
value = r_dist(r_eng);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(reverse) {
|
||||||
|
auto value_str = isAlt ? value_to_korean_alt(value) : value_to_korean(value);
|
||||||
|
printf("\nGot Korean form \"");
|
||||||
|
std::cout.write((char*)value_str.c_str(), value_str.size());
|
||||||
|
std::cout << "\"";
|
||||||
|
} else {
|
||||||
|
printf("\nGot value \"");
|
||||||
|
printValue(value);
|
||||||
|
printf("\"");
|
||||||
|
}
|
||||||
|
printf(", hit enter to continue...");
|
||||||
|
|
||||||
std::cin.get();
|
std::cin.get();
|
||||||
|
|
||||||
std::cout << "Result: ";
|
std::cout << "Result: ";
|
||||||
|
if(reverse) {
|
||||||
|
printValue(value);
|
||||||
|
std::cout << std::endl;
|
||||||
|
} else {
|
||||||
auto value_str = isAlt ? value_to_korean_alt(value) : value_to_korean(value);
|
auto value_str = isAlt ? value_to_korean_alt(value) : value_to_korean(value);
|
||||||
std::cout.write((char*)value_str.c_str(), value_str.size());
|
std::cout.write((char*)value_str.c_str(), value_str.size());
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue