{"id":177,"date":"2024-04-26T16:25:15","date_gmt":"2024-04-26T08:25:15","guid":{"rendered":"https:\/\/seanxd.com\/?p=177"},"modified":"2024-04-26T16:25:17","modified_gmt":"2024-04-26T08:25:17","slug":"zerojudge-b186","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-b186\/","title":{"rendered":"ZeroJudge B186: Cookie, Cake, and Chocolate!"},"content":{"rendered":"<p class=\"translation-block\">There is a store currently running a promotion where customers will receive an additional box of chocolates if they buy <strong>10 cookies and 2 cakes<\/strong>. Please output the final number of items to be given away through the program.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Sample Inputs\/Outputs<\/h2>\n\n\n\n<figure class=\"wp-block-table nfd-wb-animate nfd-wb-fade-in-bottom-short\"><table class=\"has-fixed-layout\"><thead><tr><th>Sample Input(s)<\/th><th>Sample Output(s)<\/th><\/tr><\/thead><tbody><tr><td class=\"translation-block\">Each input consists of a single line containing 3 integers, representing the quantities of <strong>cookies, chocolates, and cakes<\/strong>, separated by a space.<\/td><td class=\"translation-block\">Please output the <strong>quantity of items to be given<\/strong>.\n\nThe question was made for Chinese\/Mandarin programmers, so the outputs are in Chinese. You can assume that the following output means 12 cookies, 7 chocolates, and 3 cakes. You can copy and paste the none numeral characters to output.<\/td><\/tr><tr><td>12  6  3<\/td><td>12 \u500b\u9905\u4e7e\uff0c7 \u76d2\u5de7\u514b\u529b\uff0c3 \u500b\u86cb\u7cd5\u3002<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Thought Process<\/h2>\n\n\n\n<p class=\"translation-block\">You can use a while loop, where the termination condition is if cookies are less than 10 or cakes are less than 2. If either of these conditions occurs, the loop terminates. Within the loop, simply increment the number of chocolates by 1, decrease the number of cookies by 10, and decrease the number of cakes by 2. \n\nNote: The original numbers of cookies and cakes need to be stored in two other variables that will not be modified. Finally, just output the original number of cookies and cakes along with the total number of chocolates.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Sample Code\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=b186\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge B186: Cookie, Cake, and Chocolate!<\/a><\/h3>\n\n\n\n<div class=\"hcb_wrap nfd-wb-animate nfd-wb-reveal-right nfd-delay-50\"><pre class=\"prism line-numbers lang-cpp\" data-lang=\"C++\"><code>#include &lt;iostream&gt;\nusing namespace std;\n\nint main() {\n    int cookie, cake, chocolate;\n    while (cin &gt;&gt; cookie &gt;&gt; chocolate &gt;&gt; cake)\n    {\n        int nCookie = cookie, nCake = cake;\n        while (nCookie &gt;= 10 && nCake &gt;= 2)\n        {\n            chocolate++;\n            nCookie -= 10;\n            nCake -= 2;\n        }\n        cout &lt;&lt; cookie &lt;&lt; &quot; \u500b\u9905\u4e7e\uff0c&quot; &lt;&lt; chocolate &lt;&lt; &quot; \u76d2\u5de7\u514b\u529b\uff0c&quot; &lt;&lt; cake &lt;&lt; &quot; \u500b\u86cb\u7cd5\u3002\\n&quot;;\n    }\n}\n\n\/\/ZeroJudge B186\n\/\/Dr. SeanXD<\/code><\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>\u6709\u4e00\u5bb6\u5e97\u6b63\u5728\u9032\u884c\u4fc3\u92b7\uff0c\u53ea\u8981\u5ba2\u4eba\u8cb7 10 \u500b\u9905\u4e7e\u548c 2 \u500b\u86cb\u7cd5\u5c31\u591a\u9001 1 \u76d2\u5de7\u514b\u529b\uff0c\u8acb\u4ee5\u7a0b\u5f0f\u8f38\u51fa\u6700\u5f8c\u61c9\u7d66\u4e88\u7684\u7269\u54c1 [&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":[29],"tags":[13,9],"class_list":["post-177","post","type-post","status-publish","format-standard","hentry","category-zerojudge-","tag-13","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/177","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=177"}],"version-history":[{"count":1,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/177\/revisions"}],"predecessor-version":[{"id":178,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/177\/revisions\/178"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}