第十四屆全國青少年資訊學 計算機 奧林匹克聯賽 江西賽區 初級組複賽試題

2022-01-15 01:35:01 字數 2063 閱讀 8525

1樓:百度網友

字串編輯

vars:string;

len,i,j:integer;

c,temp,temp1,a1,a2:char;

flag:boolean;

begin

readln(s);

len:=length(s);

read(c);

case c of

'd':begin

read(temp);read(a1);

for i:=1 to len do

if s[i]=a1 then

begin

flag:=true;

for j:=i+1 to len do

s[j-1]:=s[j];

dec(len);

for j:=1 to len do

write(s[j]);

break;

end;

if flag=false then writeln('error.');

end;

'i':begin

read(temp);read(a1);read(temp);read(a2);

for i:=len downto 1 do

if s[i]=a1 then

begin

flag:=true;

for j:=len downto i do

s[j+1]:=s[j];

s[i]:=a2;

inc(len);

for j:=1 to len do

write(s[j]);

break;

end;

if flag=false then writeln('error.');

end;

'r':begin

read(temp);read(a1);read(temp);read(a2);

for i:=1 to len do

if s[i]

=a1 then

begin

s[i]:=a2;flag:=true;

end;

if flag then for i:=1 to len do write(s[i]) else

write('error.');

end;

end;

end.

ab編碼:

vara,b:array[0..1000] of integer;

flag:array[0..1000] of boolean;

i,j,n,k:integer;

begin

read(k,n);

if k=1 then

begin

for i:=1 to n do read(a[i]);

b[1]:=0;

for i:=2 to n do

for j:=1 to i-1 do

if a[i]>a[j] then inc(b[i]);

write('b=(');

for i:=1 to n-1 do write(b[i],',');

writeln(b[n],')');

end else

begin

for i:=0 to n-1 do read(b[i]);

a[n-1]:=b[n-1];

flag[b[n-1]]:=true;

for i:=n-2 downto 0 do

begin

a[i]:=b[i];

while flag[a[i]]=true do inc(a[i]);

flag[a[i]]:=true;

for j:=i+1 to n-1 do

if b[i]>b[j] then inc(a[i]);

end;

write('a=(');

for i:=0 to n-2 do write(a[i],',');

writeln(a[n-1],')');

end;

end.

oj測試已通過