2024-11-13 11:08:17 +00:00
|
|
|
#include "std_lib_inc.h"
|
|
|
|
|
2024-11-20 18:18:59 +00:00
|
|
|
const vector<string> right_digit_strings = {
|
2024-11-18 16:08:16 +00:00
|
|
|
"", "ein", "zwei", "drei", "vier", "fuenf", "sechs", "sieben", "acht", "neun"
|
|
|
|
};
|
|
|
|
|
2024-11-20 18:18:59 +00:00
|
|
|
const vector<string> middle_digit_strings = {
|
2024-11-20 15:51:07 +00:00
|
|
|
"", "zehn", "zwanzig", "dreissig", "vierzig", "fuenfzig", "sechzig", "siebzig", "achzig", "neunzig"
|
|
|
|
};
|
2024-11-18 16:08:16 +00:00
|
|
|
|
2024-11-13 11:08:17 +00:00
|
|
|
int main()
|
|
|
|
{
|
2024-11-18 16:08:16 +00:00
|
|
|
int input;
|
2024-11-20 15:37:14 +00:00
|
|
|
/*
|
|
|
|
* Use while (true) with break instead of while(cin) to be able to instantly stop the loop in case of an invalid input
|
|
|
|
*/
|
2024-11-18 16:08:16 +00:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
cin >> input;
|
|
|
|
if (!cin)
|
2024-11-20 15:37:14 +00:00
|
|
|
break; // Stop running loop, if input is wrong
|
2024-11-18 16:08:16 +00:00
|
|
|
if (input < 1 || input > 999)
|
|
|
|
{
|
|
|
|
cout << "Zahl ausserhalb des gueltigen Bereichs.\n";
|
|
|
|
continue;
|
|
|
|
}
|
2024-11-20 16:24:44 +00:00
|
|
|
|
2024-11-20 17:58:57 +00:00
|
|
|
const int right_digit = input % 10;
|
|
|
|
const int middle_and_right_digit = input % 100;
|
|
|
|
const int middle_digit = ((middle_and_right_digit) - right_digit) / 10;
|
2024-11-18 16:27:55 +00:00
|
|
|
|
|
|
|
vector<string> result;
|
2024-11-20 18:03:17 +00:00
|
|
|
string number_constructor = "";
|
2024-11-20 17:58:57 +00:00
|
|
|
if (middle_and_right_digit < 11 || middle_and_right_digit > 12)
|
2024-11-20 15:37:14 +00:00
|
|
|
{
|
|
|
|
// Handle everything else
|
2024-11-20 17:58:57 +00:00
|
|
|
if (right_digit == 1)
|
2024-11-20 18:03:17 +00:00
|
|
|
number_constructor = "s";
|
2024-11-20 17:58:57 +00:00
|
|
|
if (middle_digit > 1 && right_digit != 0)
|
2024-11-20 18:03:17 +00:00
|
|
|
number_constructor = "und";
|
2024-11-20 18:07:34 +00:00
|
|
|
number_constructor = right_digit_strings[right_digit] + number_constructor;
|
2024-11-20 15:37:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Handle 11 and 12
|
2024-11-20 17:58:57 +00:00
|
|
|
if (middle_and_right_digit == 11)
|
2024-11-20 18:03:17 +00:00
|
|
|
number_constructor = "elf";
|
2024-11-20 15:37:14 +00:00
|
|
|
else
|
2024-11-20 18:03:17 +00:00
|
|
|
number_constructor = "zwoelf";
|
2024-11-20 15:37:14 +00:00
|
|
|
}
|
2024-11-20 18:03:17 +00:00
|
|
|
result.push_back(number_constructor);
|
2024-11-20 15:37:14 +00:00
|
|
|
|
2024-11-20 17:58:57 +00:00
|
|
|
if ((input > 9 /*input_length > 1*/) && (middle_and_right_digit < 11 || middle_and_right_digit > 12))
|
2024-11-18 16:27:55 +00:00
|
|
|
result.push_back(middle_digit_strings[middle_digit]);
|
|
|
|
else
|
|
|
|
result.push_back("");
|
2024-11-18 16:08:16 +00:00
|
|
|
|
2024-11-20 16:24:44 +00:00
|
|
|
if (input > 99 /*input_length >= 3*/)
|
2024-11-18 16:08:16 +00:00
|
|
|
{
|
2024-11-20 17:58:57 +00:00
|
|
|
int left_digit = ((input % 1000) - middle_digit) / 100;
|
|
|
|
if (left_digit != 1)
|
2024-11-20 18:07:34 +00:00
|
|
|
number_constructor = right_digit_strings[left_digit];
|
2024-11-20 17:43:38 +00:00
|
|
|
else
|
2024-11-20 18:03:17 +00:00
|
|
|
number_constructor = "";
|
|
|
|
result.push_back(number_constructor + "hundert");
|
2024-11-18 16:08:16 +00:00
|
|
|
}
|
2024-11-18 16:27:55 +00:00
|
|
|
else
|
|
|
|
result.push_back("");
|
2024-11-18 16:08:16 +00:00
|
|
|
|
2024-11-18 16:27:55 +00:00
|
|
|
cout << result[2] << result[0] << result[1] << "\n";
|
2024-11-18 16:08:16 +00:00
|
|
|
}
|
|
|
|
cout << "Eingabe beendet.\n";
|
2024-11-13 11:08:17 +00:00
|
|
|
return 0;
|
2024-11-18 16:08:16 +00:00
|
|
|
}
|