Untitled
unknown
csharp
2 years ago
1.8 kB
36
Indexable
using System;
using System.Collections.Generic;
namespace ConsoleApplication1 {
internal class Program {
static string[] units = {
"", "jeden", "dwa", "trzy", "cztery", "pięć", "sześć",
"siedem", "osiem", "dziewięć",
"dziesięć", "jedenaście", "dwanaście", "trzynaście",
"czternaście", "piętnaście", "szesnaście", "siedemnaście",
"osiemnaście", "dziewiętnaście"
};
static string[] tens = {
"", "", "dwadzieścia", "trzydzieści", "czterdzieści",
"pięćdziesiąt", "sześćdziesiąt",
"siedemdziesiąt", "osiemdziesiąt", "dziewięćdziesiąt"
};
static string[] hundreds = {
"", "sto", "dwieście", "trzysta", "czterysta", "pięćset",
"sześćset", "siedemset", "osiemset", "dziewięćset"
};
static int getBiggestNumberConversion(int x) {
if (x == 1_000_000) {
Console.Write("jeden milion");
return 0;
}
var unit = 3;
for (var i = 0; i <= 3; i++) {
if (Math.Pow(10, i) > x) {
unit = i - 1;
break;
}
}
if (x < 20) unit = 0;
switch (unit) {
case 0:
Console.Write(units[x] + " ");
return x;
case 1:
Console.Write(tens[x / 10] + " ");
return (x / 10) * 10;
case 2:
Console.Write(hundreds[x / 100] + " ");
return (x / 100) * 100;
case 3:
var thousands = x / 1000;
if (thousands > 1) getNumberConversion(thousands);
if (thousands == 1) Console.Write("tysiąc ");
else if ((thousands > 1) && (thousands < 5))
Console.Write("tysiące ");
else Console.Write("tysięcy ");
return thousands * 1000;
default:
return 0;
}
}
static void getNumberConversion(int x) {
while (x > 0) {
x -= getBiggestNumberConversion(x);
}
}
private static void Main() {
int a;
Console.Write("Podaj liczbę arabską: ");
a = Convert.ToInt32(Console.ReadLine());
getNumberConversion(a);
}
}
}Editor is loading...
Leave a Comment