3,977 questions
I found it too. A possible conversion:
static ref class Roman
{
static initonly Dictionary<wchar_t, int>^ RomanNumberDictionary;
static Roman( )
{
RomanNumberDictionary = gcnew Dictionary<wchar_t, int>;
RomanNumberDictionary['I'] = 1;
RomanNumberDictionary['V'] = 5;
RomanNumberDictionary['X'] = 10;
RomanNumberDictionary['L'] = 50;
RomanNumberDictionary['C'] = 100;
RomanNumberDictionary['D'] = 500;
RomanNumberDictionary['M'] = 1000;
}
public:
static int From( String^ roman )
{
int total = 0;
int current, previous = 0;
wchar_t currentRoman, previousRoman = L'\0';
for( int i = 0; i < roman->Length; i++ )
{
currentRoman = roman[i];
previous = previousRoman != L'\0' ? RomanNumberDictionary[previousRoman] : L'\0';
current = RomanNumberDictionary[currentRoman];
if( previous != 0 && current > previous )
{
total = total - ( 2 * previous ) + current;
}
else
{
total += current;
}
previousRoman = currentRoman;
}
return total;
}
};
// Example:
// Console::WriteLine( Roman::From( "MMXXIII" ) );