2017.8.8测试 题二 字符串的展开
题解:本题是一道有点烦的模拟题,只要耐心点,题目要你怎么样,你去实现就行了。
var
len:array[1..100]of longint;
sss:array[1..100]of string;
s,ss:string;
p1,p2,p3,lenn,o,oo,i,j:longint;
procedure try(x,y:longint);
var
ss:string;
j,k,z:longint;
begin
j:=0;
if (y-x<26) and (y-x>0) then//确保是同一类型且不相等
begin
j:=1;
ss:='';
delete(sss[i],len[i],1);//把-删掉
write(sss[i]);
if y-x=1 then exit;//右边是左边的后继只删-输出就行了~
if p3=1 then//顺着输出
begin
for k:=x+1 to y-1 do
for z:=1 to p2 do//重复个数
if p1<>3 then ss:=ss+chr(k)
else ss:=ss+'*';//p1=3就是*了
end
else begin//逆着输出
for k:=y-1 downto x+1 do
for z:=1 to p2 do
if p1<>3 then ss:=ss+chr(k)
else ss:=ss+'*';
end;
if (p1=2) and (x>=97) then ss:=upcase(ss);//p1=2,而且不是数字就变大写
write(ss);
end;
if j<>1 then write(sss[i]);//不是同一类型或相同的就直接输出
end;
begin
readln(p1,p2,p3);
read(s);
s:=s+'-';//详见后面的判断条件
lenn:=length(s);
for i:=1 to lenn do//分开
begin
ss:=ss+s[i];
if s[i]='-' then begin//有-的分开
inc(j);
sss[j]:=ss;
len[j]:=length(sss[j]);
ss:='';
end;
end;
for i:=1 to j-1 do//最后一个的后面不用填充
begin
o:=ord(sss[i][len[i]-1]);//-左边的ascii码
oo:=ord(sss[i+1][1]);//右边的~
try(o,oo);
end;
delete(sss[j],len[j],1);//删掉自己加的-
write(sss[j]);
end.