题解 P1321 【单词覆盖还原】

· · 题解

简单至极


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.