{"id":58,"date":"2022-01-12T15:40:00","date_gmt":"2022-01-12T07:40:00","guid":{"rendered":"http:\/\/www.doogi.cn\/?p=58"},"modified":"2022-12-28T10:47:40","modified_gmt":"2022-12-28T02:47:40","slug":"turing-coding-challenge","status":"publish","type":"post","link":"http:\/\/www.doogi.cn\/?p=58","title":{"rendered":"Turing Coding Challenge"},"content":{"rendered":"\n<pre lang=\"csharp\" line=\"1\">\n\/\/ int[] nums = { 1, 2, 3, 4, 5 };\n\/\/ \u6839\u636e\u6570\u7ec4\u751f\u6210\u6240\u6709\u53ef\u80fd\u7684\u5b50\u6570\u7ec4\n\/\/ \u6b64\u4f8b\u4e3a12345 1234 123 12 1 2345 234 23 2 345 34 3 45 4 5\nstatic IList<ilist<int>> test3(int[] nums)\n{\n\tIList<ilist<int>> result = new List<ilist<int>>();\n\n\tfor (int i = 0; i < nums.Length; i++)\n\t{\n\t\tList<int> list = new List<int>(nums);\n\t\tfor (int j = 0; j < i; j++)\n\t\t{\n\t\t\tlist.RemoveAt(0);\n\t\t}\n\n\t\tfor (int k = 0; k < list.Count; k++)\n\t\t{\n\t\t\tList<int> list2 = new List<int>(list);\n\t\t\tfor (int l = 0; l < k; l++)\n\t\t\t{\n\t\t\t\tif (list2.Count > 0)\n\t\t\t\t\tlist2.RemoveAt(list2.Count - 1);\n\t\t\t}\n\t\t\tresult.Add(list2);\n\t\t}\n\t}\n\treturn result;\n}\n\/\/ string mes = \"{()[]}\";\n\/\/ \u5224\u65ad\u5b57\u7b26\u4e32\u5185\u7684\u5404\u79cd\u62ec\u53f7\u662f\u5426\u7b26\u5408\u89c4\u5219\nstatic bool test2(string mes)\n{\n\tList<char> list = new List<char>();\n\tforeach (char c in mes)\n\t{\n\t\tif (c == '{' || c == '[' || c == '(')\n\t\t{\n\t\t\tlist.Add(c);\n\t\t}\n\t\telse if (c == '}')\n\t\t{\n\t\t\tif (list.Last() != '{')\n\t\t\t\treturn false;\n\t\t\tlist.RemoveAt(list.Count - 1);\n\t\t}\n\t\telse if (c == ']')\n\t\t{\n\t\t\tif (list.Last() != '[')\n\t\t\t\treturn false;\n\t\t\tlist.RemoveAt(list.Count - 1);\n\t\t}\n\t\telse if (c == ')')\n\t\t{\n\t\t\tif (list.Last() != '(')\n\t\t\t\treturn false;\n\t\t\tlist.RemoveAt(list.Count - 1);\n\t\t}\n\t}\n\treturn list.Count == 0;\n}\n\n\/\/ string[] mes = { \"5\", \"-2\", \"4\", \"C\", \"D\", \"9\", \"+\", \"+\" };\n\/\/ \u6839\u636e\u5b57\u7b26\u6570\u636e\u505a\u8fd0\u7b97 \nstatic int test1(string[] mes)\n{\n\tList<int> list = new List<int>();\n\tforeach (string s in mes)\n\t{\n\t\tConsole.WriteLine(s);\n\t\tif (s == \"C\")\n\t\t{\n\t\t\tif (list.Count > 0)\n\t\t\t\tlist.RemoveAt(list.Count - 1);\n\t\t}\n\t\telse if (s == \"D\")\n\t\t{\n\t\t\tif (list.Count > 0)\n\t\t\t{\n\t\t\t\tint a = list.Last();\n\t\t\t\tlist.Add(a * 2);\n\t\t\t}\n\t\t}\n\t\telse if (s == \"+\")\n\t\t{\n\t\t\tif (list.Count > 1)\n\t\t\t{\n\t\t\t\tint a = list.Last();\n\t\t\t\tint b = list[list.Count - 2];\n\t\t\t\tlist.Add(a + b);\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tlist.Add(int.Parse(s));\n\t\t}\n\t}\n\treturn list.Sum();\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\/\/ int[] nums = { 1, 2, 3, 4, 5 }; \/\/ \u6839\u636e\u6570\u7ec4\u751f\u6210\u6240\u6709\u53ef\u80fd\u7684\u5b50\u6570\u7ec4 \/\/ &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.doogi.cn\/?p=58\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201cTuring Coding Challenge\u201d<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-58","post","type-post","status-publish","format-standard","hentry","category-development"],"_links":{"self":[{"href":"http:\/\/www.doogi.cn\/index.php?rest_route=\/wp\/v2\/posts\/58"}],"collection":[{"href":"http:\/\/www.doogi.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.doogi.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.doogi.cn\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.doogi.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=58"}],"version-history":[{"count":3,"href":"http:\/\/www.doogi.cn\/index.php?rest_route=\/wp\/v2\/posts\/58\/revisions"}],"predecessor-version":[{"id":110,"href":"http:\/\/www.doogi.cn\/index.php?rest_route=\/wp\/v2\/posts\/58\/revisions\/110"}],"wp:attachment":[{"href":"http:\/\/www.doogi.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=58"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.doogi.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=58"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.doogi.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=58"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}