Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Thanks for @ubs121
Dictionary<long, string> num = new Dictionary<long, string>() {
{0, "" }, { 1, "нэг" }, { 2, "хоёр" }, {3,"гурав"}, {4, "дөрөв"}, {5, "тав"}, {6,"зургаа"}, {7,"долоо"}, {8,"найм"}, {9,"ес"},
{10, "арав"}, {20,"хорь"},{30,"гуч"}, {40,"дөч"}, {50,"тавь"}, {60,"жар"}, {70,"дал"}, {80,"ная"}, {90,"ер"},
{100,"зуу"},{200,"хоёр зуу"},{300,"гурван зуу"},{400,"дөрвөн зуу"},{500,"таван зуу"},{600,"зургаан зуу"},{700,"долоон зуу"},{800,"найман зуу"},{900,"есөн зуу"}
};
Dictionary<long, string> sep_num = new Dictionary<long, string>()
{
{3,"мянга"},
{6,"сая"},
{9,"тэрбум"},
{12,"наяд"}
};
public string num2text(long n)
{
if (n == 0)
{
return "тэг";
}
List<String> words = new List<string>();
long p = 0;
long d1, d2, d3;
while (n > 0)
{
if (sep_num.ContainsKey(p))
{
words.Add(sep_num[p]);
}
else if (p > 0)
{
words.Add("{нэргүй}");
}
// a = (d3 d2 d1)
int a = (int)(n % 1000);
d1 = a % 10;
d2 = (a / 10) % 10;
d3 = a / 100;
words.Add(num[d1]);
words.Add(num[d2 * 10]);
words.Add(num[d3 * 100]);
n = n / 1000;
p += 3;
}
// холбогч нэрсээр солих
StringBuilder result = new StringBuilder();
for (int i = words.Count - 1; i > 0; i--)
{
if (words[i].Length > 0)
{
result.Append(makeBander(words[i]) + " ");
}
}
result.Append(words[0]);
return result.ToString();
}
Dictionary<string, string> bander = new Dictionary<string, string>() {
{"гурав","гурван"},{"дөрөв","дөрвөн"},{"тав","таван"},{"зургаа","зургаан"},{"долоо","долоон"},{"найм","найман"},{"ес","есөн"},
{"арав","арван"},{"хорь","хорин"},{"гуч","гучин"},{"дөч","дөчин"},{"тавь","тавин"},{"жар","жаран"},{"дал","далан"},{"ная","наян"},{"ер","ерэн"},
{"зуу","зуун"}
};
private string makeBander(string w)
{
if (bander.ContainsKey(w))
{
return bander[w];
}
else if (w.EndsWith("зуу"))
{
return w + "н";
}
return w;
}

hi bi chinii ene script php huruulj ajiluulsan um tegsen boldoggui ee herew php haraad meddeg bol zasaad uguuchee

'', 1 => 'нэг', 2 => 'хоёр', 3 => 'гурав', 4 => 'дөрөв', 5 => 'тав', 6 => 'зургаа', 7 => 'долоо', 8 => 'найм', 9 => 'ес', 10 => 'арав', 20 => 'хорь', 30 => 'гуч', 40 => 'дөч', 50 => 'тавь', 60 => 'жар', 70 => 'дал', 80 => 'ная', 90 => 'ер', 100 => 'зуу', 200 => 'хоёр зуу', 300 => 'гурван зуу', 400 => 'дөрвөн зуу', 500 => 'таван зуу', 600 => 'зургаан зуу', 700 => 'долоон зуу', 800 => 'найман зуу', 900 => 'есөн зуу' ); $sep_num = array( 3 => 'мянга', 6 => 'сая', 9 => 'тэрбум', 12 => 'наяд' ); if ($number == 0) { return "тэг"; } $words = array(); $p = 0; while ($number > 0) { if (array_key_exists($p, $sep_num)) { $words[] = $sep_num[$p]; } else if ($p > 0) { $words[] = "{нэргүй}"; } ``` $a = (int)($number % 1000); $d1 = $a % 10; $d2 = ($a / 10) % 10; $d3 = $a / 100; $words[] = $num[$d1]; $words[] = $num[$d2 * 10]; $words[] = $num[$d3 * 100]; $number = $number / 1000; $p += 3; } // холбогч нэрсээр солих $result = ""; for ($i = count($words) - 1; $i > 0; $i--) { if (strlen($words[$i]) > 0) { $result .= makeBander($words[$i]) + " "; } } return $result; } ``` function makeBander($word) { $bander = array( 'гурав' => 'гурван', 'дөрөв' => 'дөрвөн', 'тав' => 'таван', 'зургаа' => 'зургаан', 'долоо' => 'долоон', 'найм' => 'найман', 'ес' => 'есөн', 'арав' => 'арван', 'хорь' => 'хорин', 'гуч' => 'гучин', 'дөч' => 'дөчин', 'тавь' => 'тавин', 'жар' => 'жаран', 'дал' => 'далан', 'ная' => 'наян', 'ер' => 'ерэн', 'зуу' => 'зуун' ); if (array_key_exists($word, $bander)) { return $bander[$word]; } elseif (endsWithChar($word, 'зуу')) { return $word + "н"; } return $word; } function endsWithChar($needle, $haystack) { return ($needle[strlen($needle) - 1] === $haystack); } echo convert_number_to_words(10); //echo makeBander('ыбүйыбөүруу'); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment