Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
number to words in lithuanian
//Title of this code //Rextester.Program.Main is the entry point for your code. Don't change it. using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { //Your code goes here Console.WriteLine(GetNumberInWords("54")); } public static string GetNumberInWords(string n) { if (string.IsNullOrEmpty(n)) return ""; int number = Convert.ToInt32(n); if(number == 0) return "nulis"; int type = 0; int remainder = number; string res = ""; if (number % 100 > 9 && number % 100 < 20) { res = GetPartInWords(number % 100, 1); type = 2; remainder = number / 100; } while (remainder != 0) { type++; int factor = 10; if(type >= 4) factor = 1000; res = GetPartInWords(remainder % factor, type).Trim() + " " + res.Trim(); remainder = remainder / factor; } return res; } static string GetPartInWords(int number, int type) { if (type == 1) //0-19 { switch (number) { case 1: return "vienas"; case 2: return "du"; case 3: return "trys"; case 4: return "keturi"; case 5: return "penki"; case 6: return "šeši"; case 7: return "septyni"; case 8: return "aštuoni"; case 9: return "devyni"; case 10: return "dešimt"; case 11: return "vienuolika"; case 12: return "dvylika"; case 13: return "trylika"; case 14: return "keturiolika"; case 15: return "penkiolika"; case 16: return "šešiolika"; case 17: return "septyniolika"; case 18: return "aštuoniolika"; case 19: return "devyniolika"; } } if (type == 2) //20,30,40,50,60,70,80,90 { switch (number) { case 2: return "dvidešimt"; case 3: return "trisdešimt"; case 4: return "keturiasdešimt"; case 5: return "penkiasdešimt"; case 6: return "šešiasdešimt"; case 7: return "septyniasdešimt"; case 8: return "aštuoniasdešimt"; case 9: return "devyniasdešimt"; } } if (type == 3) //100, 200, 300, 400, 500, 600, 700, 800, 900 { switch (number) { case 1: return "vienas šimtas"; case 2: return "du šimtai"; case 3: return "trys šimtai"; case 4: return "keturi šimtai"; case 5: return "penki šimtai"; case 6: return "šeši šimtai"; case 7: return "septyni šimtai"; case 8: return "aštuoni šimtai"; case 9: return "devyni šimtai"; } } if (type == 4) //tūkstančiai { if(number % 1000 != 0) { List<string> vns_vardininkas = new List<string>() { "01", "21", "31", "41", "51", "61", "71", "81", "91" }; List<string> kilmininkas = new List<string>() { "00", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "30", "40", "50", "60", "70", "80", "90" }; var last_two = (number % 100).ToString().PadLeft(2, '0'); var word = "tūkstančiai"; if(vns_vardininkas.Contains(last_two)) word = "tūkstantis"; if(kilmininkas.Contains(last_two)) word = "tūkstančių"; return GetNumberInWords(number.ToString()).Trim()+" "+word.Trim(); } else { return ""; } } if (type == 5) //milijonai { if(number % 1000 != 0) { List<string> vns_vardininkas = new List<string>() { "01", "21", "31", "41", "51", "61", "71", "81", "91" }; List<string> kilmininkas = new List<string>() { "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "30", "40", "50", "60", "70", "80", "90" }; var last_two = (number % 100).ToString().PadLeft(2, '0'); var word = "milijonai"; if(vns_vardininkas.Contains(last_two)) word = "milijonas"; if(kilmininkas.Contains(last_two)) word = "milijonų"; return GetNumberInWords(number.ToString()).Trim()+" "+word.Trim(); } else { return ""; } } if (type == 6) //milijardai { if(number % 1000 != 0) { List<string> vns_vardininkas = new List<string>() { "01", "21", "31", "41", "51", "61", "71", "81", "91" }; List<string> kilmininkas = new List<string>() { "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "30", "40", "50", "60", "70", "80", "90" }; var last_two = (number % 100).ToString().PadLeft(2, '0'); var word = "milijardai"; if(vns_vardininkas.Contains(last_two)) word = "milijardas"; if(kilmininkas.Contains(last_two)) word = "milijardų"; return GetNumberInWords(number.ToString()).Trim()+" "+word.Trim(); } else { return ""; } } return ""; } } }
run
|
edit
|
history
|
help
0
Lambdas
Creating async methods in C# prior to version 5.0
Evo Ivana da budes fancy :D
Main Math
linked list reversal recursive
diagonal
NeedFirst
Working (C# thing)
GeneGenerator
IEquatable_resolved