ngắn hơn nhiều:
uses crt;
var st:string;
d,i,x,y,s:integer;
begin
clrscr;
write('nhap so la ma:'); readln(st);
s:=0;
d:=length(st);
for i:=1 to d do
begin
case st of
'I':x:=1;
'V':x:=5;
'X':x:=10;
'L':x:=50;
'C':x:=100;
'D':x:=500;
'M':x:=1000;
end;
case st[i+1]of
'I':y:=1;
'V':y:=5;
'X':y:=10;
'L':y:=50;
'C':y:=100;
'D':y:=500;
'M':y:=1000;
end;
if x<y then begin
s:=s-x;
end
else if x>=y then s:=s+x;
end;
write(s);
readln;
end.