- 数字反转
- 2017-10-28 09:31:16 @
var
a,i,k,j:int64;
s:string;
t:char;
pd:boolean;
begin
read(a);
if a=0 then
begin
write('0');
halt;
end;
str(a,s);
k:=length(s);
if s[1]='-' then pd:=true;
i:=1;
j:=k;
repeat
t:=s[i];
s[i]:=s[j];
s[j]:=t;
inc(i);dec(j);
until i>=j;
i:=0;
repeat
inc(i);
if s[i]='0' then
delete(s,i,1);
until s[i]<>'0';
if pd=true then
begin
delete(s,length(s),1);
insert('-',s,1);
end;
write(s);
end.
0 条评论
目前还没有评论...