using System.Collections.Generic;
public class RomanContext
public int Input { get; set; }
public string Output { get; set;}
public RomanContext(int input)
public interface RomanExpression
void Interpret(RomanContext context);
public class RomanOneExpression: RomanExpression
public void Interpret(RomanContext context)
while(context.Input - 9 >= 0)
while(context.Input - 5 >= 0)
while(context.Input - 4 >= 0)
while(context.Input - 1 >= 0)
public class RomanTenExpression: RomanExpression
public void Interpret(RomanContext context)
while(context.Input - 90 >= 0)
while(context.Input - 50 >= 0)
while(context.Input - 40 >= 0)
while(context.Input - 10 >= 0)
public class RomanHundredExpression: RomanExpression
public void Interpret(RomanContext context)
while(context.Input - 900 >= 0)
while(context.Input - 500 >= 0)
while(context.Input - 400 >= 0)
while(context.Input - 100 >= 0)
public static void Main()
List<RomanExpression> expressions = new()
new RomanHundredExpression(),
new RomanTenExpression(),
var context = new RomanContext(input);
foreach(var expression in expressions)
expression.Interpret(context);
Console.WriteLine($"Roman representation for {input} is {context.Output}");
context = new RomanContext(input);
foreach(var expression in expressions)
expression.Interpret(context);
Console.WriteLine($"Roman representation for {input} is {context.Output}");
context = new RomanContext(input);
foreach(var expression in expressions)
expression.Interpret(context);
Console.WriteLine($"Roman representation for {input} is {context.Output}");