比赛 暑假培训一 评测结果 AAAATWAWWW
题目名称 字符串的展开 最终得分 50
用户昵称 Oo湼鞶oO 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-07-17 09:28:47
显示代码纯文本
program expand(input,output,i,o);
var
  p1,p2,p3,w:byte;
  j:char;
  r,l:record
    z:char;
    x:(dx,xx,sz);
    end;
  d:array[1..125]of char;
  s:string;
  k,t,u:integer;
  i,o:text;
begin
  assign(i,'expand.in');
  reset(i);
  readln(i,p1,p2,p3);
  readln(i,s);
  close(i);
  assign(o,'expand.out');
  rewrite(o);
  if s[1]='-'
  then
  begin
    write(o,'-');
    delete(s,1,1);
  end;
  repeat
    w:=pos('-',s);
    l.z:=s[w-1];
    r.z:=s[w+1];
    case ord(l.z) of
      48..57:l.x:=sz;
      97..122:l.x:=xx;
      65..90:l.x:=dx;
    end;
    case ord(r.z) of
      48..57:r.x:=sz;
      97..122:r.x:=xx;
      65..90:r.x:=dx;
    end;
    if (l.x<>r.x)or(ord(l.z)>=ord(r.z))
    then
    begin
      insert('+',s,w+1);
      delete(s,w,1);
    end
    else
      if (l.x=r.x)and(abs(ord(l.z)-ord(r.z))=1)
      then
        delete(s,w,1)
      else
      begin
        k:=0;
        for j:=chr(ord(l.z)+1) to chr(ord(r.z)-1) do
        begin
          inc(k);
          d[k]:=j;
        end;
        if (p1=1)and(l.x=dx)
        then
          for t:=1 to k do
            d[t]:=chr(ord(d[t])+32);
        if (p1=2)and(l.x=xx)
        then
          for t:=1 to k do
            d[t]:=chr(ord(d[t])-32);
        if p1=3
        then
          for t:=1 to k do
            d[t]:='*';
        if p3=2
        then
          for t:=1 to k do
            for u:=1 to p2 do
              insert(d[t],s,w+1)
        else
          for t:=k downto 1 do
            for u:=1 to p2 do
              insert(d[t],s,w+1);
        delete(s,w,1);
      end;
  until(pos('-',s)=0);
  for k:=1 to length(s) do
    if s[k]='+' then write(o,'-')
                else write(o,s[k]);
  close(o);
end.