讨论 / 不使用数组……一次搞定
fdiqecvhihrqt 2008-09-22 04:54:00
点我顶贴 收藏 删除
不使用数组……一次搞定

代码仅供参考:

var

n,x,y,t,i,p:longint;

st:string;

flag:boolean;

begin

readln(n);

x:=0;

y:=0;

t:=0;

flag:=false;

for i:=1 to n do begin

readln(st);

if pos(’t’,st)=0 then begin

val(st,p);

case t of

0:y:=y+p;

1:x:=x+p;

2:y:=y-p;

3:x:=x-p;

end;

if true then begin

writeln(’(’,x,’,’,y,’)’);

flag:=true;

end;

end

else begin

if st=’right’ then t:=(t+1) mod 4

else t:=(t+3) mod 4;

end;

end;

if not flag then writeln(’(0,0)’);

end.

#1 woshiniba@2008-09-22 04:54:00
回复 删除
我的源程序,差不多,为何才10分……:

program af;

var

n,a,b,i,m,t,man,fangx:longint; st:string;

begin

read(n); fangx:=0; a:=0; b:=0; man:=0;

for i:=1 to n do

begin

readln(st);

if st=’left’ then fangx:=(fangx+3) mod 4

else if st=’right’ then fangx:=(fangx+1) mod 4

else begin

val(st,t);

man:=1;

case fangx of

1:a:=a+t;

2:b:=b-t;

3:a:=a-t;

0:b:=b+t;

end;

writeln(’(’,a,’,’,b,’)’);

end;

end;

if man=0 then writeln(’(0,0)’);

end.

查看更多回复
提交回复