不是VIP会员,不能显示答案

题目解答

题目:
program Gxp1;
var i , n , jr , jw , jb : integer ;
ch1: char ;
ch: array[1..20] of char ;
begin
readln(n);
for i:=1 to n do read(ch[i]);
jr:=1; jw:=n; jb:=n;
while (jr<=jw) do
begin
if (ch[jw]=’R’)
then begin
ch1:=ch[jr]; ch[jr]:=ch[jw]; ch[jw]:=ch1; jr:=jr+1;
end
else if ch[jw]=’W’
then jw:=jw-1;
else begin
ch1:=ch[jw]; ch[jw]:=ch[jb]; ch[jb]:=ch1; jw:=jw-1; jb:=jb-1;
end
end;
for i:=1 to n do write(ch[1]);
writeln;
end.
输入:10
RBRBWWRBBR
输出:RRRRWWBBBB
考点:
分析:
解答:
评论:
老师: