NOIP2007 字符串的展开

坑人的题目啊~~~~~,虽然说是个模拟题,但是还不是那么好拿分的,一定要细心。
本人的得分顺序:第一次40,第二次50,第三次90,第四次100……
本题需要注意的地方,也是题目中没有说明的地方(要靠选手的理解能力了):
1:只有减号两侧同为数字或同为字母时才能展开。
2:减号可以位于字符串的头部,也可以位于字符串的尾部。
3:减号可以是一个,也可以是多个。

PS:另开一个字符串变量ans,直接记录答案,不用在原字串上操作。


program expand;

var
	p1,p2,p3:longint;
	s,ans:ansistring;

procedure init;
begin
	ans:='';
	readln(p1,p2,p3);
	readln(s);
end;

procedure main;
var
	i,k,c:longint;
	j:char;
	temp:ansistring;
begin
	for i:=1 to length(s) do
		begin
			if s[i]<>'-' then ans:=ans+s[i];
			if s[i]='-' then
				begin
					c:=0;
					if i=length(s) then
						begin
							ans:=ans+'-';
							continue;
						end;
					if i=1 then 
						begin
							ans:=ans+'-';
							continue;
						end;
					if (s[i+1]='-') or (s[i-1]='-') then 
						begin
							ans:=ans+'-';
							continue;
						end;
					if ((ord(s[i-1])>=48) and (ord(s[i-1])<=57) and (ord(s[i+1])>=65) and (ord(s[i+1])<=122)) or ((ord(s[i+1])>=48) and (ord(s[i+1])<=57) and (ord(s[i-1])>=65) and (ord(s[i-1])<=122)) then 
						begin
							ans:=ans+'-';
							continue;
						end;
					if ord(s[i-1])=ord(s[i+1])-1 then continue;
					if s[i-1]>=s[i+1] then 
						begin
							ans:=ans+s[i];
							continue;
						end;
					if s[i-1]<s[i+1] then
						begin
							if (ord(s[i-1])-48>=0) and (ord(s[i-1])-48<=10) then c:=32;							
							temp:='';
							if p3=1 then
								begin
									for j:=chr(ord(s[i-1])+1) to chr(ord(s[i+1])-1) do
										begin
											for k:=1 to p2 do
												begin
													if p1=1 then temp:=temp+j;
													if p1=2 then temp:=temp+chr(ord(j)-32+c);
													if p1=3 then temp:=temp+'*';
												end;
										end;
								end;
							if p3=2 then
								begin
									for j:=chr(ord(s[i+1])-1) downto chr(ord(s[i-1])+1) do
										begin
											for k:=1 to p2 do
												begin
													if p1=1 then temp:=temp+j;
													if p1=2 then temp:=temp+chr(ord(j)-32+c);
													if p1=3 then temp:=temp+'*';
												end;
										end;									
								end;
							ans:=ans+temp;
						end;
				end;
		end;
end;

begin
	assign(input,'expand.in'); reset(input);
	assign(output,'expand.out'); rewrite(output);

	init;
	main;
	writeln(ans);

	close(input); close(output);
end.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值