比赛 |
20100914 |
评测结果 |
AAAWAWAAAA |
题目名称 |
算24点 |
最终得分 |
80 |
用户昵称 |
苏轼 |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2010-09-14 19:39:06 |
显示代码纯文本
- program point24(input,output);
-
- var
- n:array[1..4]of integer;
- s:array[1..3]of string;
- s1,s2:string;
- i,tmp:integer;
-
- function go(sum,deep:integer):boolean;
- var
- i,flag,ans:integer;
- ch:char;
- begin
- ch:=#0;
-
- if deep<4 then
- begin
- inc(deep);
-
- for i:=1 to 4 do
- if n[i]<>0 then
- begin
- flag:=n[i];
- n[i]:=0;
-
- if go(sum+flag,deep) then
- begin
- ans:=sum+flag;
- ch:='+';
- end
- else if (sum>=flag) and go(sum-flag,deep) then
- begin
- ans:=sum-flag;
- ch:='-';
- end
- else if go(sum*flag,deep) then
- begin
- ans:=sum*flag;
- ch:='*';
- end
- else if (sum mod flag=0)and go(sum div flag,deep) then
- begin
- ans:=sum div flag;
- ch:='/';
- end;
-
- n[i]:=flag;
-
- if ch<>#0 then
- begin
- flag:=i;
- break;
- end;
- end;
- end
- else
- exit(sum=24);
-
- dec(deep);
- if ch<>#0 then
- begin
- str(sum,s1);
- str(n[i],s2);
- str(ans,s[deep]);
-
- if sum>n[i] then
- s[deep]:=s1+ch+s2+'='+s[deep]
- else
- s[deep]:=s2+ch+s1+'='+s[deep];
-
- exit(true);
- end
- else
- exit(false);
- end;
-
- begin
- assign(input,'point24.in');
- reset(input);
-
- assign(output,'point24.out');
- rewrite(output);
-
- readln(n[1],n[2],n[3],n[4]);
-
- for i:=1 to 4 do
- begin
- tmp:=n[i];
- n[i]:=0;
-
- if go(tmp,1) then
- break;
-
- n[i]:=tmp;
- end;
-
- if s[1]<>'' then
- for i:=1 to 3 do
- writeln(s[i])
- else
- writeln('No answer!');
-
- close(input);
- close(output);
- end.
-
-