using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
Dictionary<string, int> romanNumbers = new Dictionary<string, int>();
public int RomanToInt(string s)
romanNumbers.Add("I", 1);
romanNumbers.Add("V", 5);
romanNumbers.Add("X", 10);
romanNumbers.Add("L", 50);
romanNumbers.Add("C", 100);
romanNumbers.Add("D", 500);
romanNumbers.Add("M", 1000);
for (int i=0; i < s.Length; i++)
if (s[i] == 'I' && s[i] != s.Last() && ((s[i + 1] == 'V') || (s[i + 1] == 'X')))
else if (s[i] == 'X' && s[i] != s.Last() && ((s[i + 1] == 'L') || (s[i + 1] == 'C')))
else if (s[i] == 'C' && s[i] != s.Last() && ((s[i + 1] == 'D') || (s[i + 1] == 'M')))
FinalNum += turnRomanCharToInt(s[i]);
Console.WriteLine(FinalNum);
public int turnRomanCharToInt(char ch)
var myKey = romanNumbers.FirstOrDefault(x => x.Key == ch.ToString()).Value;
public static void Main()
Solution solution = new Solution();