比赛 20100914 评测结果 AAAWAWAAAA
题目名称 算24点 最终得分 80
用户昵称 donny 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-09-14 20:12:05
显示代码纯文本
  1. program point24(input,output);
  2. var
  3. a:array[1..4]of integer;
  4. b:array[1..4]of boolean;
  5. c:array[0..4]of integer;
  6. d:array[1..4]of char;
  7. i,j,k,l:integer;
  8. procedure search(x,y:integer);
  9. var
  10. i,j,k:integer;
  11. begin
  12. if x=4 then
  13. begin
  14. if y=24 then
  15. begin
  16. k:=c[1];
  17. for i:=1 to 3 do
  18. begin
  19. case d[i] of
  20. '+': j:=k+c[i+1];
  21. '-': j:=k-c[i+1];
  22. '*': j:=k*c[i+1];
  23. '/': j:=k div c[i+1];
  24. end;
  25. if k>c[i+1] then
  26. writeln(k,d[i],c[i+1],'=',j)
  27. else
  28. writeln(c[i+1],d[i],k,'=',j);
  29. k:=j;
  30. end;
  31. close(input);
  32. close(output);
  33. halt;
  34. end;
  35. end
  36. else
  37. begin
  38. for i:=1 to 4 do
  39. if b[i] then
  40. begin
  41. b[i]:=false;
  42. inc(c[0]);
  43. c[c[0]]:=a[i];
  44. if x=0 then search(x+1,a[i])
  45. else
  46. begin
  47. d[x]:='+';
  48. search(x+1,y+a[i]);
  49. if y-a[i]>0 then
  50. begin
  51. d[x]:='-';
  52. search(x+1,y-a[i]);
  53. end;
  54. d[x]:='*';
  55. search(x+1,y*a[i]);
  56. if y mod a[i]=0 then
  57. begin
  58. d[x]:='/';
  59. search(x+1,y div a[i]);
  60. end;
  61. end;
  62. b[i]:=true;
  63. dec(c[0]);
  64. end;
  65. end;
  66. end;
  67. begin
  68. assign(input,'point24.in');
  69. reset(input);
  70. assign(output,'point24.out');
  71. rewrite(output);
  72.  
  73. for i:=1 to 4 do
  74. read(a[i]);
  75. for i:=1 to 4 do
  76. b[i]:=true;
  77. search(0,0);
  78. writeln('No answer!');
  79. close(input);
  80. close(output);
  81. end.