- 等价表达式
- 2013-08-29 22:40:34 @
var ss,sss:string;
s,s1:array[-1..206] of string;
suan:array[-1..206] of longint;
n:longint;
t:array[-1..261] of boolean;
opf:array[-1..1001] of char;
ops:array[-1..1001] of longint;
topf,tops:longint;
//
procedure init;
var i:longint;
c:char;
begin
assign(input,'p1003.in');assign(output,'p1003.out');
reset(input);rewrite(output);
readln(sss);
readln(n);
for i:=1 to n do readln(s[i]);
close(input);
end;
//
procedure stri(k:integer;var s:string);
var l:integer;
s1:string;
begin
l:=0;
while (pos('a',s)<>0) do
begin
l:=pos('a',s);
str(k,s1);
delete(s,l,1);insert(s1,s,l);
end;
end;
//
procedure pushf(c:char);
begin
inc(topf);opf[topf]:=c;
end;
//
procedure pushs(s:longint);
begin
inc(tops);ops[tops]:=s;
end;
//
function pops:longint;
begin
pops:=ops[tops];
dec(tops);
end;
//
function popf:char;
begin
popf:=opf[topf];
dec(topf);
end;
//
function jisuan(a,b:longint;c:char):longint;
var i:longint;
begin
case c of
'+':exit((a+b) mod maxint);
'-':exit((a-b) mod maxint);
'*':exit((a*b) mod maxint);
'^':begin
jisuan:=a;i:=1;
while i<>b do
begin
inc(i);jisuan:=(jisuan*a) mod maxint;
end;
end;
end;
end;
//
function wei(c:char):integer;
begin
case c of
'-','+':exit(1);
'*':exit(2);
'^':exit(3);
')':exit(4);
'(':exit(0);
end;
end;
//
function exp(s:string):longint;
var i,l,p:longint;
j:longint;
begin
topf:=0;tops:=0;
while s<>'' do
begin
l:=1;while s[1]=' ' do delete(s,1,1);
while (s[l]>='0') and (s[l]<='9') do inc(l);
if (l=1) then
begin
if (s[1]=')') then
begin
while (opf[topf]<>'(') and (topf>0) do pushs(jisuan(pops,pops,popf));
if (topf<>0) then dec(topf);
end;
while (wei(s[1])<=wei(opf[topf])) and (topf>=1) and (opf[topf]<>'(') and (s[1]<>'(') do pushs(jisuan(pops,pops,popf));
if s[1]<>')' then pushf(s[1]); delete(s,1,1);
end
else begin
val(copy(s,1,l-1),j,p);pushs(j);delete(s,1,l-1);
end;
end;
while topf>0 do
begin
while (opf[topf]='(') and (topf>0) do dec(topf);
pushs(jisuan(pops,pops,popf));
end;
exit(ops[1]);
end;
//
procedure main;
var i,j:longint;
begin
for i:=1 to 20 do
begin
s1:=s;ss:=sss;
stri(i,ss);
for j:=1 to n do stri(i,s1[j]);
suan[0]:=exp(ss) mod maxint;
for j:=1 to n do
begin
suan[j]:=exp(s1[j]) mod maxint;
if suan[0]<>suan[j] then t[j]:=true;
end;
end;
end;
//
procedure print;
var i:longint;
begin
for i:=1 to n do
if not(t[i]) then write(chr(i+ord('A')-1));
close(output);
end;
//
begin
init;
main;
print;
end.
3 条评论
-
liyueze LV 8 @ 2013-08-31 18:05:50
评测机又不会有“in”,“out”的文件,改成直接输入。
-
2013-08-30 10:06:41@
var ss,sss:string;
s,s1:array[-1..206] of string;
suan:array[-1..206] of longint;
n:longint;
t:array[-1..261] of boolean;
opf:array[-1..1001] of char;
ops:array[-1..1001] of longint;
topf,tops:longint;
//
procedure init;
var i:longint;
c:char;
begin
//assign(input,'p1003.in');assign(output,'p1003.out');
//reset(input);rewrite(output);
readln(sss);
readln(n);
for i:=1 to n do readln(s[i]);
close(input);
end;
//
procedure stri(k:integer;var s:string);
var l:integer;
s1:string;
begin
l:=0;
while (pos('a',s)<>0) do
begin
l:=pos('a',s);
str(k,s1);
delete(s,l,1);insert(s1,s,l);
end;
end;
//
procedure pushf(c:char);
begin
inc(topf);opf[topf]:=c;
end;
//
procedure pushs(s:longint);
begin
inc(tops);ops[tops]:=s;
end;
//
function pops:longint;
begin
pops:=ops[tops];
dec(tops);
end;
//
function popf:char;
begin
popf:=opf[topf];
dec(topf);
end;
//
function jisuan(a,b:longint;c:char):longint;
var i:longint;
begin
case c of
'+':exit((a+b) mod maxint);
'-':exit((a-b) mod maxint);
'':exit((a*b) mod maxint);
'^':begin
jisuan:=a;i:=1;
while i<>b do
begin
inc(i);jisuan:=(jisuan*a) mod maxint;
end;
end;
end;
end;
//
function wei(c:char):integer;
begin
case c of
'-','+':exit(1);
'':exit(2);
'^':exit(3);
')':exit(4);
'(':exit(0);
end;
end;
//
function exp(s:string):longint;
var i,l,p:longint;
j:longint;
begin
topf:=0;tops:=0;
while s<>'' do
begin
l:=1;while s[1]=' ' do delete(s,1,1);
while (s[l]>='0') and (s[l]<='9') do inc(l);
if (l=1) then
begin
if (s[1]=')') then
begin
while (opf[topf]<>'(') and (topf>0) do pushs(jisuan(pops,pops,popf));
if (topf<>0) then dec(topf);
end;
while (wei(s[1])<=wei(opf[topf])) and (topf>=1) and (opf[topf]<>'(') and (s[1]<>'(') do pushs(jisuan(pops,pops,popf));
if s[1]<>')' then pushf(s[1]); delete(s,1,1);
end
else begin
val(copy(s,1,l-1),j,p);pushs(j);delete(s,1,l-1);
end;
end;
while topf>0 do
begin
while (opf[topf]='(') and (topf>0) do dec(topf);
pushs(jisuan(pops,pops,popf));
end;
exit(ops[1]);
end;
//
procedure main;
var i,j:longint;
begin
for i:=1 to 20 do
begin
s1:=s;ss:=sss;
stri(i,ss);
for j:=1 to n do stri(i,s1[j]);
suan[0]:=exp(ss) mod maxint;
for j:=1 to n do
begin
suan[j]:=exp(s1[j]) mod maxint;
if suan[0]<>suan[j] then t[j]:=true;
end;
end;
end;
//
procedure print;
var i:longint;
begin
for i:=1 to n do
if not(t[i]) then write(chr(i+ord('A')-1));
close(output);
end;
//
begin
init;
main;
print;
end. -
2013-08-30 08:17:10@
貌似不应该用文件腱操作
- 1