版本比较
题解 P4908 【小奔上课】
正文
增加 17 行删除 17 行
21 行未改动22232425262726272829303152 行未改动848586878888899091928 行未改动10110210310410510510610710810915 行未改动1251261271281291291301311321339 行未改动1431441451461471471481491491501511521539 行未改动16316416516616716816716816917017117217317417517517617717817817918018118210 行未改动1931941951961971971981992002012022032042042052062072082 行未改动21121221321421521621521621721821922011 行未改动2322332342352362362372382392402412422422432442452466 行未改动21 行未改动 check0:=false; if (q=1)and((s[q+1]>='0')and(s[q+1]<='9')) then exit; if (q=1) then begin check0:=true; exit; end;//数字首尾不能是零,否则算式首位都能放0 if (q=length(s)) then begin if (q=length(s)) then begin check0:=true; exit; end;//最后一位只要能放数字就能放零52 行未改动 if (s[n]='(')or(s[n]=')') then begin i:=n+1; while (s[i]<>'(')and(s[i]<>')') do begin if ((s[i]='*')and(i<>q))or(s[i]='/')or((s[i]='-')and((s[i-1]>='0')and(s[i-1]<='9')))or(s[i]='+') then if ((s[i]='*')and(i<>q))or(s[i]='/')or((s[i]='-')and((s[i-1]>='0')and(s[i-1]<='9')))or(s[i]='+') then begin checks:=true; if (q=1)or(q=length(s)) then exit; if (s[q-1]=')')or(s[q+1]='(') then begin checks:=false; exit; end;8 行未改动 if (s[m]='(')or(s[m]=')') then begin i:=m-1; while (s[i]<>'(')and(s[i]<>')') do begin if ((s[i]='*')and(i<>q))or(s[i]='/')or((s[i]='-')and((s[i-1]>='0')and(s[i-1]<='9')))or(s[i]='+') then if ((s[i]='*')and(i<>q))or(s[i]='/')or((s[i]='-')and((s[i-1]>='0')and(s[i-1]<='9')))or(s[i]='+') then begin checks:=true; if (q=1)or(q=length(s)) then exit; if (s[q-1]=')')or(s[q+1]='(') then begin checks:=false; exit; end;15 行未改动end;procedure pop(s:string);begin dec(p); case symbol[p+1] of case symbol[p+1] of '+':number[p]:=number[p]+number[p+1]; '-':number[p]:=number[p]-number[p+1]; '*':number[p]:=number[p]*number[p+1]; '/':begin9 行未改动 if (s[i] in ['*','/'])and (symbol[p] in ['*','/']) then exit; can:=false;end;function js(s:string):real;var var t:string; j,code:longint; j,code:longint;begin s:='('+s+')'; i:=1; p:=0;9 行未改动 inc(i); until (s[i]<'0')or (s[i]>'9'); t:=copy(s,j,i-j); val(t,number[p],code); repeat if s[i]=')' then repeat if s[i]=')' then begin while symbol[p]<>'(' do pop(s); dec(p); number[p]:=number[p+1]; end else begin while can(s) do while can(s) do begin pop(s); if b then begin if b then begin js:=min+(max-min)/2; b:=false; exit; end;10 行未改动var i:real;begin if o>m then begin i:=js(st); i:=js(st); if i>max then max:=i; if i<min then min:=i; exit;//求最大值和最小值 end; if checks(a[o],st) then begin if check0(a[o],st) then if check0(a[o],st) then begin st[a[o]]:='0'; zx(o+1,st); end;2 行未改动 st[a[o]]:='9'; zx(o+1,st);//能放23456就能放19,并且19得出的值比23456等数都大 end; if (a[o]=length(st))or((st[a[o]-1]='-')and(st[a[o]-2]='-'))or(st[a[o]+1]=')') then i:=0 if (a[o]=length(st))or((st[a[o]-1]='-')and(st[a[o]-2]='-'))or(st[a[o]+1]=')') then i:=0//这里除了极端条件(如:--*)不能放-外,都能放- else begin st[a[o]]:='-';11 行未改动begin readln(ss); max:=-maxlongint-1; min:=maxlongint; for j:=1 to length(ss) do if ss[j]='*' then for j:=1 to length(ss) do if ss[j]='*' then begin inc(m); a[m]:=j;//记录每一个残缺位置 end; if m=0 then if m=0 then begin writeln(js(ss)); halt; end;6 行未改动