var s:ansistring;
d,a:array['A'..'Z'] of longint;
x,y,i,tx,ty,k:longint;
c:char;
procedure nhap;
begin
readln(tx,ty);
readln(s);
end;
procedure b1;
begin
x:=0;y:=0;
for i:=1 to length(s) do
begin
if s[i]='U' then inc(y);
if s[i]='D' then dec(y);
if s[i]='R' then inc(x);
if s[i]='L' then dec(x);
if s[i]='?' then inc(k);
end;
end;
procedure b2;
begin
if (x>=tx) then
begin
d['L']:=x-tx;
dec(k,d['L']);
end
else
begin
d['R']:=tx-x;
dec(k,d['R']);
end;
if (y>=ty) then
begin
d['D']:=y-ty;
dec(k,d['D']);
end
else
begin
d['U']:=ty-y;
dec(k,d['U']);
end;
end;
procedure b3;
begin
if k<0 then
begin
write('IMPOSSIBLE');
halt;
end
else
begin
if k mod 2=0 then
begin
inc(d['D'],k div 2);
inc(d['U'],k div 2);
end
else
begin
write('IMPOSSIBLE');
halt;
end;
end;
end;
procedure b4;
begin
for i:=1 to length(s) do
begin
if s[i]='?' then
begin
for c:='D' to 'U' do
begin
if d[c]>0 then
begin
s[i]:=c;
dec(d[c]);
break;
end;
end;
end;
end;
write(s);
end;
begin
assign(input,'journey.inp');reset(input);
assign(output,'journey.out');rewrite(output);
nhap;
b1;
b2;
b3;
b4;
end.
* Chuyên dạy lập trình ONLINE cho học sinh THCS, THPT *.
Mọi giao lưu, trao đổi, xin liên hệ: Lê Quang Vinh - zalo: 037.803.8755.
Page: Lớp học Code Sky
Group FB1: Ôn thi HSG9 - THTB - TS10 chuyên tin
Group FB2: Học Scratch - Ôn thi Tin học trẻ bảng A
Thứ Tư, 27 tháng 4, 2022
JOURNEY Pascal
Đăng ký:
Đăng Nhận xét (Atom)
Không có nhận xét nào:
Đăng nhận xét
Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.