a013.
羅馬數字
--
NPSC 模擬試題
| From: [58.33.95.65] |
發表日期
:
2014-01-19 23:16
var
i,j,k:longint;
s:string;
numbers:array[1..3999] of string;
n,t:longint;
m:array[1..4] of string;
five:array[1..3] of string;
input:string;
space:longint;
a,b:string;
an,bn:longint;
ans:longint;
begin
while not eof do
begin
m[1]:='I'; five[1]:='V';
m[2]:='X'; five[2]:='L';
m[3]:='C'; five[3]:='D';
m[4]:='M';
for i:=1 to 3999 do
begin
numbers[i]:='';
str(i,s);
for j:=1 to length(s) do
begin
case s[j] of
'1'..'3': begin
val(s[j],n);
t:=length(s)-j+1;
for k:=1 to n do
begin
numbers[i]:=numbers[i]+m[t];
end;
end;
'4': begin
t:=length(s)-j+1;
numbers[i]:=numbers[i]+m[t]+five[t];
end;
'5'..'8': begin
val(s[j],n);
n:=n-5;
t:=length(s)-j+1;
numbers[i]:=numbers[i]+five[t];
for k:=1 to n do
begin
numbers[i]:=numbers[i]+m[t];
end;
end;
'9': begin
t:=length(s)-j+1;
numbers[i]:=numbers[i]+m[t]+m[t+1];
end;
end;
end;
end;
readln(input);
space:=pos(' ',input);
a:=copy(input,1,space-1);
b:=copy(input,space+1,length(input));
for i:=1 to 4000 do
if numbers[i]=a then
begin
an:=i;
break;
end;
for i:=1 to 4000 do
if numbers[i]=b then
begin
bn:=i;
break;
end;
ans:=an-bn;
if ans<>0 then writeln(numbers[ans])
else writeln('ZERO');
end;
end.