记录编号 275 评测结果 AAAAAAAAAA
题目名称 [NOIP 2007]字符串的展开 最终得分 100
用户昵称 GravatarEnAsn 是否通过 通过
代码语言 Pascal 运行时间 0.032 s
提交时间 2008-07-18 12:12:28 内存使用 0.11 MiB
显示代码纯文本
program ex;
var
 f1,f2:text;
 s,s1:string;
 p1,p2,p3:integer;
 n,l:integer;
 x,y:char;
procedure init;
 begin
  assign(f1,'expand.in');
  assign(f2,'expand.out');
  reset(f1);
  rewrite(f2);
  readln(f1,p1,p2,p3);
  readln(f1,s);
 end;
procedure tch(var s1:string;p1,p2,p3:integer;x,y:char);
 var
  i:char;
  j:integer;
 begin
  inc(x);dec(y);
  if p3=1 then
    begin
     case p1 of
      1: begin
           for i:=x to y do
             for j:=1 to p2 do
               s1:=s1+i;
         end;
      2: begin
             if (x in['0'..'9'])and(y in['0'..'9']) then
                        for i:=x to y do
                          for j:=1 to p2 do
                           s1:=s1+i
                   else for i:=char(ord(x)-32) to char(ord(y)-32) do
                         for j:=1 to p2 do
                           s1:=s1+i;
         end;
      3: begin
           for i:=x to y do
            for j:=1 to p2 do
             s1:=s1+'*';
         end;
     end;
    end
    else begin
           case p1 of
             1: begin
                 for i:=y downto x do
                   for j:=1 to p2 do
                    s1:=s1+i;
                end;
             2: begin
                 if (x in['0'..'9'])and(y in['0'..'9']) then
                        for i:=y downto x do
                          for j:=1 to p2 do
                           s1:=s1+i
                   else for i:=char(ord(y)-32) downto char(ord(x)-32) do
                         for j:=1 to p2 do
                           s1:=s1+i;
                end;
             3: begin
                 for i:=x to y do
                   for j:=1 to p2 do
                     s1:=s1+'*';
                end;
           end;
         end;
 end;
procedure pd(x,y:char);
 var
  z:char;
 begin
   z:=x;
   inc(x);
   if x=y then write(f2,s1)
              else if (z>=y)
                        or(z in['0'..'9'])and(y in['a'..'z'])
                         or(z in['a'..'z'])and(y in['0'..'9'])
                          or(z='-')or(y='-')
                           then write(f2,s1,'-')
                           else begin
                                  tch(s1,p1,p2,p3,z,y);
                                  write(f2,s1);
                                end;
 end;
begin
 init;
 if s[1]='-' then begin
                 delete(s,1,1);
                 write(f2,'-');
                end;
 n:=pos('-',s);
 while n<>0 do begin
   if (n=1) then
     begin
       write(f2,'-');
       delete(s,1,n);
     end;
   n:=pos('-',s);
   if n=0 then break;
   x:=s[n-1];
   y:=s[n+1];
   s1:=copy(s,1,n-1);
   delete(s,1,n);
   pd(x,y);
   n:=pos('-',s);
 end;
 write(f2,s);
 close(f1);
 close(f2);
end.