using System;
using System.Collections.Generic;
public class Test
{
public static Dictionary<string,int> NumDict;
public static Dictionary<string,int> MilharDict;
public static int ExtensoToInteiro(string extenso)
{
if (NumDict == null)
{
NumDict = new Dictionary<string,int>();
MilharDict = new Dictionary<string,int>();
NumDict.Add("zero",0);
NumDict.Add("um",1);
NumDict.Add("dois",2);
NumDict.Add("três",3);
NumDict.Add("quatro",4);
NumDict.Add("cinco",5);
NumDict.Add("seis",6);
NumDict.Add("sete",7);
NumDict.Add("oito",8);
NumDict.Add("nove",9);
NumDict.Add("dez",10);
NumDict.Add("onze",11);
NumDict.Add("doze",12);
NumDict.Add("treze",13);
NumDict.Add("quatorze",14);
NumDict.Add("quinze",15);
NumDict.Add("dezesseis",16);
NumDict.Add("dezessete",17);
NumDict.Add("dezoito",18);
NumDict.Add("dezenove",19);
NumDict.Add("vinte",20);
NumDict.Add("trinta",30);
NumDict.Add("quarenta",40);
NumDict.Add("cinquenta",50);
NumDict.Add("sessenta",60);
NumDict.Add("setenta",70);
NumDict.Add("oitenta",80);
NumDict.Add("noventa",90);
NumDict.Add("cem",100);
NumDict.Add("cento",100);
NumDict.Add("duzentos",200);
NumDict.Add("trezentos",300);
NumDict.Add("quatrocentos",400);
NumDict.Add("quinhentos",500);
NumDict.Add("seiscentos",600);
NumDict.Add("setecentos",700);
NumDict.Add("oitocentos",800);
NumDict.Add("novecentos",900);
MilharDict.Add("mil",1000);
MilharDict.Add("milhão",1000000);
MilharDict.Add("milhões",1000000);
MilharDict.Add("bilhão",1000000000);
MilharDict.Add("bilhões",1000000000);
}
int resultado = 0;
int grupoCorrente = 0;
foreach (var word in extenso.Split(' '))
{
if (NumDict.ContainsKey(word))
{
grupoCorrente += NumDict[word];
}
else if (MilharDict.ContainsKey(word))
{
resultado += (grupoCorrente == 0 ? 1 : grupoCorrente) * MilharDict[word];
grupoCorrente = 0;
}
}
resultado += grupoCorrente;
return resultado;
}
public static void Main()
{
Console.WriteLine(ExtensoToInteiro("trinta mil e um real"));
}
}
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TnVtRGljdC5BZGQoInF1YXRvcnplIiwxNCk7CgkgICAgICAgIE51bURpY3QuQWRkKCJxdWluemUiLDE1KTsKCSAgICAgICAgTnVtRGljdC5BZGQoImRlemVzc2VpcyIsMTYpOwoJICAgICAgICBOdW1EaWN0LkFkZCgiZGV6ZXNzZXRlIiwxNyk7CgkgICAgICAgIE51bURpY3QuQWRkKCJkZXpvaXRvIiwxOCk7CgkgICAgICAgIE51bURpY3QuQWRkKCJkZXplbm92ZSIsMTkpOwoJCgkgICAgICAgIE51bURpY3QuQWRkKCJ2aW50ZSIsMjApOwoJICAgICAgICBOdW1EaWN0LkFkZCgidHJpbnRhIiwzMCk7CgkgICAgICAgIE51bURpY3QuQWRkKCJxdWFyZW50YSIsNDApOwoJICAgICAgICBOdW1EaWN0LkFkZCgiY2lucXVlbnRhIiw1MCk7CgkgICAgICAgIE51bURpY3QuQWRkKCJzZXNzZW50YSIsNjApOwoJICAgICAgICBOdW1EaWN0LkFkZCgic2V0ZW50YSIsNzApOwoJICAgICAgICBOdW1EaWN0LkFkZCgib2l0ZW50YSIsODApOwoJICAgICAgICBOdW1EaWN0LkFkZCgibm92ZW50YSIsOTApOwoJCgkgICAgICAgIE51bURpY3QuQWRkKCJjZW0iLDEwMCk7CgkgICAgICAgIE51bURpY3QuQWRkKCJjZW50byIsMTAwKTsgCgkgICAgICAgIE51bURpY3QuQWRkKCJkdXplbnRvcyIsMjAwKTsKCSAgICAgICAgTnVtRGljdC5BZGQoInRyZXplbnRvcyIsMzAwKTsKCSAgICAgICAgTnVtRGljdC5BZGQoInF1YXRyb2NlbnRvcyIsNDAwKTsKCSAgICAgICAgTnVtRGljdC5BZGQoInF1aW5oZW50b3MiLDUwMCk7CgkgICAgICAgIE51bURpY3QuQWRkKCJzZWlzY2VudG9zIiw2MDApOwoJICAgICAgICBOdW1EaWN0LkFkZCgic2V0ZWNlbnRvcyIsNzAwKTsKCSAgICAgICAgTnVtRGljdC5BZGQoIm9pdG9jZW50b3MiLDgw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