Sorting the Roman Number

Hello everyone,

Can you help me to sort by ascending the roman number?

Example: V, I, IX, XI
Expected Result: I, V, IX, XI

one of many options:

translate the romanian number to an integer. Just parse each character and sum it up. e.g with a help of a switch activity:


            case 'I':return 1;
            case 'V':return 5;
            case 'X':return 10;
            case 'L':return 50;
            case 'C':return 100;
            case 'D':return 500;
            case 'M':return 1000;
            default:throw new Exception("Invalid Roman Number.");

But also handle the IV which results to 4 and not 1+5

For handling both representations we can use a dicitionary (key= Romanian Number, Value = the integer value) and can sort it on the integer values (e.g. with the help of LINQ)

1 Like

Depending on your selected target framework, there also some packages available doing this conversion e.g.

and also more

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.