{"id":1039,"date":"2024-08-05T09:00:00","date_gmt":"2024-08-05T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=1039"},"modified":"2024-06-30T12:36:25","modified_gmt":"2024-06-30T04:36:25","slug":"zerojudge-a308","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-a308\/","title":{"rendered":"ZeroJudge A308: Counting Words"},"content":{"rendered":"\n\n\n<p>\u4e00\u822c\u7684\u6587\u672c\u7de8\u8f2f\u5668\u90fd\u6709\u67e5\u627e\u55ae\u8a5e\u7684\u529f\u80fd\uff0c\u8a72\u529f\u80fd\u53ef\u4ee5\u5feb\u901f\u5b9a\u4f4d\u7279\u5b9a\u55ae\u8a5e\u5728\u6587\u7ae0\u4e2d\u7684\u4f4d\u7f6e\uff0c\u6709\u7684\u9084\u80fd\u7d71\u8a08\u51fa\u7279\u5b9a\u55ae\u8a5e\u5728\u6587\u7ae0\u4e2d\u51fa\u73fe\u7684\u6b21\u6578\u3002<\/p>\n\n\n\n<p>\u73fe\u5728\uff0c\u8acb\u4f60\u7de8\u7a0b\u5be6\u73fe\u9019\u4e00\u529f\u80fd\uff0c\u5177\u9ad4\u8981\u6c42\u662f\uff1a\u7d66\u5b9a\u4e00\u500b\u55ae\u8a5e\uff0c\u8acb\u4f60\u8f38\u51fa\u5b83\u5728\u7d66\u5b9a\u7684\u6587\u7ae0\u4e2d\u51fa\u73fe\u7684\u6b21\u6578\u548c\u7b2c\u4e00\u6b21\u51fa\u73fe\u7684\u4f4d\u7f6e\u3002\u6ce8\u610f\uff1a\u5339\u914d\u55ae\u8a5e\u6642\uff0c\u4e0d\u5340\u5206\u5927\u5c0f\u5beb\uff0c\u4f46\u8981\u6c42\u5b8c\u5168\u5339\u914d\uff0c\u5373\u7d66\u5b9a\u55ae\u8a5e\u5fc5\u9808\u8207\u6587\u7ae0\u4e2d\u7684\u67d0\u4e00\u7368\u7acb\u55ae\u8a5e\u5728\u4e0d\u5340\u5206\u5927\u5c0f\u5beb\u7684\u60c5\u6cc1\u4e0b\u5b8c\u5168\u76f8\u540c (\u53c3\u898b\u6a23\u4f8b 1\uff09\uff0c\u5982\u679c\u7d66\u5b9a\u55ae\u8a5e\u50c5\u662f\u6587\u7ae0\u4e2d\u67d0\u4e00\u55ae\u8a5e\u7684\u4e00\u90e8\u5206\u5247\u4e0d\u7b97\u5339\u914d (\u53c3\u898b\u6a23\u4f8b 2\uff09\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7bc4\u4f8b\u6e2c\u8cc7<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7bc4\u4f8b\u8f38\u5165<\/th><th>\u7bc4\u4f8b\u8f38\u51fa<\/th><\/tr><\/thead><tbody><tr><td>\u8f38\u51652 \u884c\u3002<br>\u7b2c 1 \u884c\u70ba\u4e00\u500b\u5b57\u7b26\u4e32\uff0c\u5176\u4e2d\u53ea\u542b\u5b57\u6bcd\uff0c\u8868\u793a\u7d66\u5b9a\u55ae\u8a5e\uff1b\u7b2c 2 \u884c\u70ba\u4e00\u500b\u5b57\u7b26\u4e32\uff0c\u5176\u4e2d\u53ea\u53ef\u80fd\u5305\u542b\u5b57\u6bcd\u548c\u7a7a\u683c\uff0c\u8868\u793a\u7d66\u5b9a\u7684\u6587\u7ae0\u3002<\/td><td>\u53ea\u6709\u4e00\u884c\uff0c\u5982\u679c\u5728\u6587\u7ae0\u4e2d\u627e\u5230\u7d66\u5b9a\u55ae\u8a5e\u5247\u8f38\u51fa\u5169\u500b\u6574\u6578\uff0c\u5169\u500b\u6574\u6578\u4e4b\u9593\u7528\u4e00\u500b\u7a7a\u683c\u9694\u958b\uff0c\u5206\u5225\u662f\u55ae\u8a5e\u5728\u6587\u7ae0\u4e2d\u51fa\u73fe\u7684\u6b21\u6578\u548c\u7b2c\u4e00\u6b21\u51fa\u73fe\u7684\u4f4d\u7f6e (\u5373\u5728\u6587\u7ae0\u4e2d\u7b2c\u4e00\u6b21\u51fa\u73fe\u6642\uff0c\u55ae\u8a5e\u9996\u5b57\u6bcd\u5728\u6587\u7ae0\u4e2d\u7684\u4f4d\u7f6e\uff0c\u4f4d\u7f6e\u5f9e 0 \u958b\u59cb\uff09\uff1b\u5982\u679c\u55ae\u8a5e\u5728\u6587\u7ae0\u4e2d\u6c92\u6709\u51fa\u73fe\uff0c\u5247\u76f4\u63a5\u8f38\u51fa\u4e00\u500b\u6574\u6578 -1\u3002<\/td><\/tr><tr><td>To<br>to be or not to be is a question<br>to<br>Did the Ottoman Empire lose its power at that time<\/td><td>2 0<br>-1<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u984c\u601d\u8def<\/h2>\n\n\n\n<p>\u56e0\u70ba\u5927\u5c0f\u5beb\u8996\u70ba\u76f8\u540c\uff0c\u6240\u4ee5\u6536\u8cc7\u6599\u6642\u90fd\u8981\u5148\u5c07\u6240\u6709\u5b57\u4e32\u7d71\u4e00\u5c0f\u5beb\u6216\u5927\u5beb\u3002<\/p>\n\n\n\n<p>\u4f7f\u7528 For\u8ff4\u5708 \u4f86\u5207\u5b57\u4e32\uff0c\u9019\u908a\u4e0d\u80fd\u7528 stringstream \u662f\u56e0\u70ba\u9019\u6a23\u6703\u5ffd\u7565\u9023\u7e8c\u7684\u7a7a\u683c\u3002<\/p>\n\n\n\n<p>\u7576\u5f97\u5230\u4e00\u500b\u5b57\u4e32\u6642\uff0c\u5224\u65b7\u5176\u662f\u5426\u662f\u8981\u627e\u7684\u5b57\u4e32\uff0c\u5982\u679c\u662f\u7684\u8a71\u5c31\u8981\u5224\u65b7\u662f\u5426\u70ba\u7b2c\u4e00\u6b21\u51fa\u73fe\uff0c\u53ef\u4ee5\u5ba3\u544a\u4e00\u500b\u5e03\u6797\u503c\u4f86\u7d00\u9304\uff0c\u4e26\u4e14\u8981\u5c07\u7b54\u6848 +1\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=a308\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge A308: \u7d71\u8a08\u55ae\u8a5e\u6578<\/a><\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-cpp\" data-lang=\"C++\"><code>#include &lt;iostream&gt;\n#include &lt;vector&gt;\nusing namespace std;\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    string target;\n    while (getline(cin, target)) {\n        for (int i = 0; i&lt;target.length(); i++) target[i] = tolower(target[i]);\n        string str, tmp = &quot;&quot;;\n        getline(cin, str);\n        bool first = true;\n        int begin = 0, count = 0;\n        for (int i = 0; i&lt;str.length(); i++) {\n            if (str[i] == &#39; &#39; && !tmp.empty()) {\n                if (tmp == target) {\n                    if (first) {\n                        first = false;\n                        begin = i-target.length();\n                    }\n                    count++;\n                }\n                tmp = &quot;&quot;;\n                continue;\n            }\n            if (str[i] != &#39; &#39;) tmp += tolower(str[i]);\n        }\n        if (count == 0) cout &lt;&lt; &quot;-1\\n&quot;;\n        else cout &lt;&lt; count &lt;&lt; &quot; &quot; &lt;&lt; begin &lt;&lt; &quot;\\n&quot;;\n    }\n}\n\n\/\/ZeroJudge A308\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u822c\u7684\u6587\u672c\u7de8\u8f2f\u5668\u90fd\u6709\u67e5\u627e\u55ae\u8a5e\u7684\u529f\u80fd\uff0c\u8a72\u529f\u80fd\u53ef\u4ee5\u5feb\u901f\u5b9a\u4f4d\u7279\u5b9a\u55ae\u8a5e\u5728\u6587\u7ae0\u4e2d\u7684\u4f4d\u7f6e\uff0c\u6709\u7684\u9084\u80fd\u7d71\u8a08\u51fa\u7279\u5b9a\u55ae\u8a5e\u5728\u6587\u7ae0\u4e2d\u51fa [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","footnotes":""},"categories":[25],"tags":[8,11,34,9],"class_list":["post-1039","post","type-post","status-publish","format-standard","hentry","category-ioi-apcs","tag-8","tag-11","tag-34","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1039","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/comments?post=1039"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1039\/revisions"}],"predecessor-version":[{"id":1041,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1039\/revisions\/1041"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=1039"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=1039"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=1039"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}