public bool CheckSubstructionInside(string s) { Dictionary <char, int> roman_numbers = GetRomanNumbers(); int count_substruction = 0; int previous_value = 0; int current_value = 0; for (int i = s.Length - 1; i >= 0; i--) { current_value = roman_numbers[s[i]]; if (current_value < previous_value) { if (Math.Truncate(Math.Log(current_value, 10)) != Math.Log(current_value, 10)) { messanger?.ShowError("is not a power of 10"); return(false); } if (previous_value != current_value * 10 && current_value / 10 * 5 != previous_value / 10) { messanger?.ShowError("does not correspond to a number series"); return(false); } count_substruction++; } else if (current_value == previous_value && count_substruction > 0) { messanger?.ShowError("the number of subtractions exceeded"); return(false); } else { count_substruction = 0; } previous_value = current_value; } return(true); }