1
0

旅行.pas 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. program nta;
  2. var a:array[1..15] of 0..1;
  3. b,c:array[1..15,1..15,1..15] of 0..1;
  4. i,j,k,l,l1,l2,l3,n,num,ok:integer;
  5. x:boolean;
  6. str:string;
  7. f1,f2:text;
  8. procedure init;
  9. begin
  10. assign(f1,'nta6.dat');
  11. assign(f2,'nta.out');
  12. reset(f1);
  13. rewrite(f2);
  14. readln(f1,n);
  15. end;
  16. procedure clean;
  17. begin
  18. for j:=1 to 15 do a[j]:=0;
  19. for j:=1 to 15 do
  20. for k:=1 to 15 do
  21. for l:=1 to 15 do
  22. begin
  23. b[j,k,l]:=0;
  24. c[j,k,l]:=0;
  25. end;
  26. x:=false;
  27. end;
  28. procedure read_file;
  29. begin
  30. read(f1,num);
  31. readln(f1,ok);
  32. for j:=num-ok+1 to num do a[j]:=1;
  33. for j:=1 to num do
  34. for k:=1 to num do
  35. begin
  36. readln(f1,str);
  37. for l:=1 to length(str) do
  38. b[j,k,ord(str[l])-96]:=1;
  39. end;
  40. readln(f1,str);
  41. for j:=1 to length(str)-1 do
  42. c[length(str)-1,j,ord(str[j])-96]:=1;
  43. end;
  44. procedure try;
  45. begin
  46. for j:=length(str)-1 downto 1 do
  47. for k:=1 to j do
  48. for l1:=1 to num do
  49. if c[j+1,k,l1]=1 then
  50. for l2:=1 to num do
  51. if c[j+1,k+1,l2]=1 then
  52. for l3:=1 to num do
  53. if b[l1,l2,l3]=1 then
  54. c[j,k,l3]:=1;
  55. for j:=num-ok+1 to num do
  56. if c[1,1,j]=1 then x:=true;
  57. end;
  58. procedure write_file;
  59. begin
  60. if x then writeln(f2,'accept')
  61. else writeln(f2,'reject');
  62. end;
  63. procedure close_file;
  64. begin
  65. close(f1);
  66. close(f2);
  67. end;
  68. begin
  69. init;{打开文件}
  70. for i:=1 to n do
  71. begin
  72. clean;{清0}
  73. read_file;{读入数据}
  74. try;{判断过程}
  75. write_file;{写入文件}
  76. end;
  77. close_file;{关闭文件}
  78. end.