关于加减表达式求和的疑惑
pascal吧
全部回复
仅看楼主
level 1
zhuyingshang1 楼主
var bj,ans,tmp,i:longint;
st:string;
begin
readln(st);
for i:=1 to length(st) do
if st[i]in['-','+'] then begin
case bj of
0:ans:=ans+tmp;
1:ans:=ans-tmp;
end;
case st[i] of
'+':bj:=0;
'-':bj:=1;
end;
tmp:=0;
end
else tmp:=tmp*10+ord(st[i])-48;
case bj of
0:ans:=ans+tmp;
1:ans:=ans-tmp;
end;
writeln(ans);
end.
tmp:=tmp*10+ord(st[i])-48; 这行是什么意思?
2016年06月25日 07点06分 1
level 7
*10-st[i] 就这么简单别想太多 -48是因为要转换
2016年06月25日 09点06分 2
好的 谢谢[吐舌]
2016年06月26日 09点06分
level 7
+
2016年06月25日 09点06分 3
1