{"id":603,"date":"2009-08-31T22:09:00","date_gmt":"2009-08-31T02:09:00","guid":{"rendered":""},"modified":"2009-08-31T22:09:00","modified_gmt":"2009-08-31T02:09:00","slug":"","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/603.html","title":{"rendered":"\u4e5d\u5bab\u683c\u7b97\u6cd5\u5b9e\u73b0(Delphi\u7248\u672c)"},"content":{"rendered":"<p><html><head><meta http-equiv=\"Content-Type\" content=\"text\/html; charset=utf-8\" \/><title>\u4e5d\u5bab\u683c\u7b97\u6cd5\u5b9e\u73b0(Delphi\u7248\u672c)<\/title><\/head><body><\/p>\n<h1 style=\"display:none\">\u4e5d\u5bab\u683c\u7b97\u6cd5\u5b9e\u73b0(Delphi\u7248\u672c)<\/h1>\n<div>\n<p>\u53d1\u73b0\u7528Delphi\u5199\u51fa\u6765\u7684\u6bd4\u7528C\u5199\u51fa\u6765\u7684\u8ba1\u7b97\u5feb\u591a\u4e86\u3002<\/p>\n<pre class=\"Delphi\"><pre><font color=\"#000080\"><strong>program<\/strong><\/font> Project1;\n<font color=\"#008284\">{$APPTYPE CONSOLE}<\/font>\n\n<font color=\"#000080\"><strong>uses<\/strong><\/font>\n  SysUtils, PerlRegEx, classes;\n\n<font color=\"#000080\"><strong>var<\/strong><\/font>\n  GG: <font color=\"#000080\"><strong>array<\/strong><\/font>[<font color=\"#0000ff\">0<\/font>..<font color=\"#0000ff\">8<\/font>] <font color=\"#000080\"><strong>of<\/strong><\/font> <font color=\"#000080\"><strong>array<\/strong><\/font>[<font color=\"#0000ff\">0<\/font>..<font color=\"#0000ff\">8<\/font>] <font color=\"#000080\"><strong>of<\/strong><\/font> Integer;\n<font color=\"#000080\"><strong>const<\/strong><\/font>\n  QQ:<font color=\"#000080\"><strong>array<\/strong><\/font>[<font color=\"#0000ff\">0<\/font>..<font color=\"#0000ff\">8<\/font>] <font color=\"#000080\"><strong>of<\/strong><\/font> integer=(<font color=\"#0000ff\">0<\/font>,<font color=\"#0000ff\">0<\/font>,<font color=\"#0000ff\">0<\/font>,<font color=\"#0000ff\">3<\/font>,<font color=\"#0000ff\">3<\/font>,<font color=\"#0000ff\">3<\/font>,<font color=\"#0000ff\">6<\/font>,<font color=\"#0000ff\">6<\/font>,<font color=\"#0000ff\">6<\/font>);\n\n<font color=\"#000080\"><strong>procedure<\/strong><\/font> SetGG;\n<font color=\"#000080\"><strong>var<\/strong><\/font>\n  f: TextFile;\n  n, m: Integer;\n  Reg: TPerlRegEx;\n  List: TStrings;\n  s: <font color=\"#000080\"><strong>string<\/strong><\/font>;\n<font color=\"#000080\"><strong>begin<\/strong><\/font>\n  Reg:=TPerlRegEx.Create(<font color=\"#000080\"><strong>nil<\/strong><\/font>);\n  List:=TStringList.Create;\n  s:=<font color=\"#0000ff\">''<\/font>;    n:=<font color=\"#0000ff\">0<\/font>;\n  AssignFile(f,<font color=\"#0000ff\">'data.txt'<\/font>);\n  Reset(f);\n  <font color=\"#000080\"><strong>while<\/strong><\/font> <font color=\"#000080\"><strong>not<\/strong><\/font> eof(f) <font color=\"#000080\"><strong>do<\/strong><\/font>\n  <font color=\"#000080\"><strong>begin<\/strong><\/font>\n    Readln(f,s); s:=trim(s);\n    <font color=\"#000080\"><strong>if<\/strong><\/font> <font color=\"#000080\"><strong>not<\/strong><\/font> (s=<font color=\"#0000ff\">''<\/font>) <font color=\"#000080\"><strong>then<\/strong><\/font>\n    <font color=\"#000080\"><strong>begin<\/strong><\/font>\n      reg.Subject := s;\n      reg.RegEx := <font color=\"#0000ff\">' *'<\/font>;\n      reg.Split(list,MaxInt);\n      <font color=\"#000080\"><strong>for<\/strong><\/font> m := <font color=\"#0000ff\">0<\/font> <font color=\"#000080\"><strong>to<\/strong><\/font> <font color=\"#0000ff\">8<\/font> <font color=\"#000080\"><strong>do<\/strong><\/font>\n      <font color=\"#000080\"><strong>begin<\/strong><\/font>\n         GG[n,m]:=strtoint(list[m]);\n      <font color=\"#000080\"><strong>end<\/strong><\/font>;\n       n:=n+<font color=\"#0000ff\">1<\/font>;\n    <font color=\"#000080\"><strong>end<\/strong><\/font>;\n  list.Clear;\n  <font color=\"#000080\"><strong>end<\/strong><\/font>;\n  list.Free;\n  closefile(f);\n<font color=\"#000080\"><strong>end<\/strong><\/font>;\n\n<font color=\"#000080\"><strong>procedure<\/strong><\/font> OutGG;\n<font color=\"#000080\"><strong>var<\/strong><\/font>\n  I: Integer;\n  j: Integer;\n<font color=\"#000080\"><strong>begin<\/strong><\/font>\n  <font color=\"#000080\"><strong>for<\/strong><\/font> I := <font color=\"#0000ff\">0<\/font> <font color=\"#000080\"><strong>to<\/strong><\/font> <font color=\"#0000ff\">9<\/font> - <font color=\"#0000ff\">1<\/font> <font color=\"#000080\"><strong>do<\/strong><\/font>\n    <font color=\"#000080\"><strong>for<\/strong><\/font> j := <font color=\"#0000ff\">0<\/font> <font color=\"#000080\"><strong>to<\/strong><\/font> <font color=\"#0000ff\">9<\/font> - <font color=\"#0000ff\">1<\/font> <font color=\"#000080\"><strong>do<\/strong><\/font>\n        <font color=\"#000080\"><strong>if<\/strong><\/font> (j&lt;&gt;<font color=\"#0000ff\">8<\/font>) <font color=\"#000080\"><strong>then<\/strong><\/font> Write(IntToStr(GG[i,j])+<font color=\"#0000ff\">' '<\/font>) <font color=\"#000080\"><strong>else<\/strong><\/font> Writeln(GG[i,j]);\n  Readln(i);\n<font color=\"#000080\"><strong>end<\/strong><\/font>;\n\n<font color=\"#000080\"><strong>function<\/strong><\/font> IsValid(i,j:integer):boolean;\n<font color=\"#000080\"><strong>var<\/strong><\/font> n,t,u:integer;\n<font color=\"#000080\"><strong>begin<\/strong><\/font>\n  Result:=true;\n  n:=GG[i,j];\n  <font color=\"#000080\"><strong>for<\/strong><\/font> t := <font color=\"#0000ff\">0<\/font> <font color=\"#000080\"><strong>to<\/strong><\/font> <font color=\"#0000ff\">9<\/font> - <font color=\"#0000ff\">1<\/font> <font color=\"#000080\"><strong>do<\/strong><\/font>\n    <font color=\"#000080\"><strong>if<\/strong><\/font>(((t&lt;&gt;i) <font color=\"#000080\"><strong>and<\/strong><\/font> (GG[t,j]=n)) <font color=\"#000080\"><strong>or<\/strong><\/font> ((t&lt;&gt;j) <font color=\"#000080\"><strong>and<\/strong><\/font> (GG[i,t]=n))) <font color=\"#000080\"><strong>then<\/strong><\/font> result:=false;\n\n  <font color=\"#000080\"><strong>for<\/strong><\/font> t := QQ[i] <font color=\"#000080\"><strong>to<\/strong><\/font> QQ[i]+<font color=\"#0000ff\">2<\/font> <font color=\"#000080\"><strong>do<\/strong><\/font>\n    <font color=\"#000080\"><strong>for<\/strong><\/font> u := QQ[j] <font color=\"#000080\"><strong>to<\/strong><\/font> QQ[j] +<font color=\"#0000ff\">2<\/font> <font color=\"#000080\"><strong>do<\/strong><\/font>\n      <font color=\"#000080\"><strong>if<\/strong><\/font>(((t&lt;&gt;i) <font color=\"#000080\"><strong>or<\/strong><\/font> (u&lt;&gt;j)) <font color=\"#000080\"><strong>and<\/strong><\/font> (GG[t,u]=n)) <font color=\"#000080\"><strong>then<\/strong><\/font> result:=false;\n<font color=\"#000080\"><strong>end<\/strong><\/font>;\n\n<font color=\"#000080\"><strong>procedure<\/strong><\/font> calc(n:integer);\n<font color=\"#000080\"><strong>var<\/strong><\/font> i,j,k:integer;\n<font color=\"#000080\"><strong>begin<\/strong><\/font>\n  <font color=\"#000080\"><strong>if<\/strong><\/font>(n=<font color=\"#0000ff\">81<\/font>) <font color=\"#000080\"><strong>then<\/strong><\/font>\n  <font color=\"#000080\"><strong>begin<\/strong><\/font>\n    OutGG;\n    Exit;\n  <font color=\"#000080\"><strong>end<\/strong><\/font>;\n\n  i:=n <font color=\"#000080\"><strong>div<\/strong><\/font> <font color=\"#0000ff\">9<\/font>; j:=n <font color=\"#000080\"><strong>mod<\/strong><\/font> <font color=\"#0000ff\">9<\/font>;\n\n  <font color=\"#000080\"><strong>if<\/strong><\/font>(GG[i,j]&lt;&gt;<font color=\"#0000ff\">0<\/font>) <font color=\"#000080\"><strong>then<\/strong><\/font>\n  <font color=\"#000080\"><strong>begin<\/strong><\/font>\n    calc(n+<font color=\"#0000ff\">1<\/font>);\n    exit;\n  <font color=\"#000080\"><strong>end<\/strong><\/font>;\n\n  <font color=\"#000080\"><strong>for<\/strong><\/font> k := <font color=\"#0000ff\">0<\/font> <font color=\"#000080\"><strong>to<\/strong><\/font> <font color=\"#0000ff\">9<\/font> - <font color=\"#0000ff\">1<\/font> <font color=\"#000080\"><strong>do<\/strong><\/font>\n  <font color=\"#000080\"><strong>begin<\/strong><\/font>\n    GG[i,j]:=GG[i,j]+<font color=\"#0000ff\">1<\/font>;\n    <font color=\"#000080\"><strong>if<\/strong><\/font>(IsValid(i,j)) <font color=\"#000080\"><strong>then<\/strong><\/font>\n    <font color=\"#000080\"><strong>begin<\/strong><\/font>\n      calc(n+<font color=\"#0000ff\">1<\/font>);\n    <font color=\"#000080\"><strong>end<\/strong><\/font>;\n  <font color=\"#000080\"><strong>end<\/strong><\/font>;\n\n  GG[i,j]:=<font color=\"#0000ff\">0<\/font>;\n\n<font color=\"#000080\"><strong>end<\/strong><\/font>;\n\n<font color=\"#000080\"><strong>begin<\/strong><\/font>\n  SetGG;\n  calc(<font color=\"#0000ff\">0<\/font>);\n  OutGG;\n<font color=\"#000080\"><strong>end<\/strong><\/font>.<\/pre>\n<\/div>\n<p><\/body><\/html><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e5d\u5bab\u683c\u7b97\u6cd5\u5b9e\u73b0(Delphi\u7248\u672c) \u4e5d\u5bab\u683c\u7b97\u6cd5\u5b9e\u73b0(Delphi\u7248\u672c) \u53d1\u73b0\u7528Delphi\u5199\u51fa\u6765\u7684\u6bd4\u7528C\u5199\u51fa\u6765 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-603","post","type-post","status-publish","format-standard","hentry","category-code_related"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/603","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=603"}],"version-history":[{"count":0,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/603\/revisions"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=603"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=603"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=603"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}