- 脑残的Ice
- 2009-10-27 18:25:15 @
program EX1;
var a,b,i,j,k,l,n,m,x,y,p,q,t:longint;
s:string;
bb:boolean;
begin
readln(s);
for i:=1 to length(s) do if s[i]'/' then a:=a*10+ord(s[i])-ord('0')
else break;
for j:=i+1 to length(s) do b:=b*10+ord(s[j])-ord('0');
readln(n);
for i:=1 to n do
begin
x:=0;y:=0;
readln(s);
l:=length(s);
if s'swap' then begin
if s[10]='z' then x:=a
else if s[10]='m' then x:=b
else for j:=7 to l do if not(s[j] in ['0'..'9']) then break
else x:=x*10+ord(s[j])-ord('0');
for j:=7 to l do if not((s[j] in['0'..'9'])or(s[j] in['A'..'Z'])or(s[j] in['a'..'z'])) then break;
m:=j;
if s[m+4]='z' then y:=a
else if s[m+4]='m' then y:=b
else for j:=m+1 to l do
y:=y*10+ord(s[j])-ord('0');
if s[4]='z' then bb:=true else bb:=false;
case s[m] of '+':p:=x+y;
'-':p:=x-y;
'*':p:=x*y;
'/':p:=trunc(x/y);
'^':begin p:=x;for q:=1 to y-1 do p:=p*x;end;
end;
if p