#include <stdio.h>
#include <conio.h>
main(){
char roman[30];
int deci=0;
int length,i,d[30];
printf("The Roman equivalent to decimal
");
printf("Decimal:.........Roman
");
printf("%5d............%3c
",1,'I');
printf("%5d............%3c
",5,'V');
printf("%5d............%3c
",10,'X');
printf("%5d............%3c
",50,'L');
printf("%5d............%3c
",100,'C');
printf("%5d............%3c
",500,'D');
printf("%5d............%3c
",1000,'M');
printf("Enter a Roman numeral:");
scanf("%s",roman);
length=strlen(roman);
for(i=0;i<length;i++){
switch(roman[i]){
case 'm':
case 'M': d[i]=1000; break;
case 'd':
case 'D': d[i]= 500; break;
case 'c':
case 'C': d[i]= 100; break;
case 'l':
case 'L': d[i]= 50; break;
case 'x':
case 'X': d[i]= 10; break;;
case 'v':
case 'V': d[i]= 5; break;
case 'i':
case 'I': d[i]= 1;
}
}
for(i=0;i<length;i++){
if(i==length-1 || d[i]>=d[i+1])
deci += d[i];
else
deci -= d[i];
}
printf("The Decimal equivalent of Roman numeral %s is %d", roman, deci);
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxjb25pby5oPgptYWluKCl7CiAgIGNoYXIgcm9tYW5bMzBdOwogICBpbnQgZGVjaT0wOwogICBpbnQgbGVuZ3RoLGksZFszMF07CiAgIHByaW50ZigiVGhlIFJvbWFuIGVxdWl2YWxlbnQgdG8gZGVjaW1hbAoiKTsKICAgcHJpbnRmKCJEZWNpbWFsOi4uLi4uLi4uLlJvbWFuCiIpOwogICBwcmludGYoIiU1ZC4uLi4uLi4uLi4uLiUzYwoiLDEsJ0knKTsKICAgcHJpbnRmKCIlNWQuLi4uLi4uLi4uLi4lM2MKIiw1LCdWJyk7CiAgIHByaW50ZigiJTVkLi4uLi4uLi4uLi4uJTNjCiIsMTAsJ1gnKTsKICAgcHJpbnRmKCIlNWQuLi4uLi4uLi4uLi4lM2MKIiw1MCwnTCcpOwogICBwcmludGYoIiU1ZC4uLi4uLi4uLi4uLiUzYwoiLDEwMCwnQycpOwogICBwcmlud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