跳到正文

题解

题解 P1321 【单词覆盖还原】

发源于约 2 分钟
原文
文章信息与版本

文章信息

发布
2013年7月2日
收录
2025年12月12日
更新
2026年11月20日
篇幅
约 2 分钟
题目
P1321

版本

  1. v1当前

简单至极

delphi
var
  s:ansistring;
  b,g,i:longint;
procedure qb(i:longint);
begin
  if s[i]='b' then s[i]:='.';
  if s[i+1]='o' then s[i+1]:='.';
  if s[i+2]='y' then s[i+2]:='.';
end;
procedure qg(i:longint);
begin
  if s[i]='g' then s[i]:='.';
  if s[i+1]='i' then s[i+1]:='.';
  if s[i+2]='r' then s[i+2]:='.';
  if s[i+3]='l' then s[i+3]:='.';
end;
begin
  readln(s);
  for i:=1 to length(s) do
    begin
      if s[i]='b' then
        begin
          inc(b);
          qb(i);
        end;
      if s[i]='o' then
        begin
          inc(b);
          qb(i-1);
        end;
      if s[i]='y' then
        begin
          inc(b);
          qb(i-2);
        end;
      if s[i]='g' then
        begin
          inc(g);
          qg(i);
        end;
      if s[i]='i' then
        begin
          inc(g);
          qg(i-1);
        end;
      if s[i]='r' then
        begin
          inc(g);
          qg(i-2);
        end;
      if s[i]='l' then
        begin
          inc(g);
          qg(i-3);
        end;
    end;
  writeln(b);
  writeln(g);
end.

原文
存档评论39 条抓取于