{"id":34340,"date":"2024-11-01T09:27:02","date_gmt":"2024-11-01T09:27:02","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=34340"},"modified":"2024-11-01T10:57:38","modified_gmt":"2024-11-01T10:57:38","slug":"c-coding-test-course-cocktail-making","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/34340\/","title":{"rendered":"C++ Coding Test Course, Cocktail Making"},"content":{"rendered":"<p><body><\/p>\n<p>This course introduces how to solve the cocktail making problem using C++. Algorithmic problems generally require generating a desired output for a specific input. This problem involves making cocktails using various ingredients according to given proportions.<\/p>\n<h2>Problem Description<\/h2>\n<p>You want to make cocktails with various ingredients. Each ingredient requires a specific amount. You want to use each ingredient to make as much cocktail as possible according to the given proportions. Calculate how many servings of cocktails you can make by properly calculating the amount and requirements of the given ingredients.<\/p>\n<h3>Input<\/h3>\n<ul>\n<li>The first line contains the number of types of ingredients N (1 \u2264 N \u2264 100).<\/li>\n<li>The second line contains the amount of each ingredient A[i] (1 \u2264 A[i] \u2264 10^5).<\/li>\n<li>The third line contains the requirement of each ingredient B[i] (1 \u2264 B[i] \u2264 10^5).<\/li>\n<\/ul>\n<h3>Output<\/h3>\n<p>Print the maximum number of servings of cocktails that can be made.<\/p>\n<h2>Example<\/h2>\n<h3>Input<\/h3>\n<pre>\n3\n100 200 300\n10 20 30\n<\/pre>\n<h3>Output<\/h3>\n<pre>\n3\n<\/pre>\n<h2>Problem Solving Approach<\/h2>\n<p>To solve this problem, you need to calculate how many servings of cocktails can be made based on the amount and requirements of each ingredient. Follow the procedure below:<\/p>\n<ol>\n<li>Calculate the possible maximum number of cocktails for each ingredient. This is the quotient of the amount of that ingredient divided by its requirement.<\/li>\n<li>Take the minimum of the maximum cocktail numbers calculated for all ingredients. This value will be the final number of cocktails that can be made.<\/li>\n<\/ol>\n<h3>C++ Code Implementation<\/h3>\n<p>Now let&#8217;s write the C++ code based on the above approach. The code will receive input, calculate the possible maximum number of cocktails for each ingredient, and output the minimum value.<\/p>\n<pre>\n#include &lt;iostream&gt;\n#include &lt;vector&gt;\n#include &lt;algorithm&gt;\nusing namespace std;\n\nint main() {\n    int N;\n    cin &gt;&gt; N; \/\/ Number of ingredient types\n    vector&lt;int&gt; A(N); \/\/ Amount of ingredients\n    vector&lt;int&gt; B(N); \/\/ Requirement of ingredients\n\n    \/\/ Input amount of ingredients\n    for (int i = 0; i &lt; N; i++) {\n        cin &gt;&gt; A[i];\n    }\n    \n    \/\/ Input requirement of ingredients\n    for (int i = 0; i &lt; N; i++) {\n        cin &gt;&gt; B[i];\n    }\n\n    int maxCocktails = INT_MAX; \/\/ Set initial value to a very large number\n\n    \/\/ Calculate maximum number of cocktails for each ingredient\n    for (int i = 0; i &lt; N; i++) {\n        int cocktailsPossible = A[i] \/ B[i]; \/\/ Possible number of cocktails\n        maxCocktails = min(maxCocktails, cocktailsPossible); \/\/ Update minimum value\n    }\n\n    cout &lt;&lt; maxCocktails &lt;&lt; endl; \/\/ Print the result\n    return 0;\n}\n    <\/pre>\n<h2>Code Explanation<\/h2>\n<p>The above C++ code calculates the maximum number of servings of cocktails through the following steps:<\/p>\n<ol>\n<li>Receive the number of ingredient types N and declare two vectors A and B to store the amount and requirement of ingredients.<\/li>\n<li>Input the amount of ingredients and input the requirement for each ingredient.<\/li>\n<li>Initialize the maximum number of cocktails to &#8216;INT_MAX&#8217; to set a comparison basis.<\/li>\n<li>Calculate the possible number of cocktails for each ingredient and store the smallest value in &#8216;maxCocktails&#8217;.<\/li>\n<li>Finally, output the calculated maximum number of cocktails.<\/li>\n<\/ol>\n<h2>Complexity Analysis<\/h2>\n<p>The time complexity of this problem is O(N). N is the number of ingredient types, and since we need to check the amount and requirements for each ingredient, it has linear time complexity. The space complexity is O(N) because two vectors are used to store the amount and requirements of ingredients.<\/p>\n<h2>Conclusion<\/h2>\n<p>In this course, we learned how to solve the cocktail making problem using C++. To solve the given problem, you need to handle input and derive desired results through calculations. This helps develop algorithmic problem-solving skills and can be useful in real coding tests.<\/p>\n<p>Expanding the problem by adding more diverse ingredients and conditions would also be good practice. I want to emphasize once again that understanding the problem and approaching it logically is important, in addition to coding.<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This course introduces how to solve the cocktail making problem using C++. Algorithmic problems generally require generating a desired output for a specific input. This problem involves making cocktails using various ingredients according to given proportions. Problem Description You want to make cocktails with various ingredients. Each ingredient requires a specific amount. You want to &hellip; <a href=\"https:\/\/atmokpo.com\/w\/34340\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;C++ Coding Test Course, Cocktail Making&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[111],"tags":[],"class_list":["post-34340","post","type-post","status-publish","format-standard","hentry","category-c-coding-test-tutorials-2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C++ Coding Test Course, Cocktail Making - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/34340\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C++ Coding Test Course, Cocktail Making - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"This course introduces how to solve the cocktail making problem using C++. Algorithmic problems generally require generating a desired output for a specific input. This problem involves making cocktails using various ingredients according to given proportions. Problem Description You want to make cocktails with various ingredients. Each ingredient requires a specific amount. You want to &hellip; \ub354 \ubcf4\uae30 &quot;C++ Coding Test Course, Cocktail Making&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/34340\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:27:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T10:57:38+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"3\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/34340\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34340\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"C++ Coding Test Course, Cocktail Making\",\"datePublished\":\"2024-11-01T09:27:02+00:00\",\"dateModified\":\"2024-11-01T10:57:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34340\/\"},\"wordCount\":492,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"C++ Coding Test Tutorials\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/34340\/\",\"url\":\"https:\/\/atmokpo.com\/w\/34340\/\",\"name\":\"C++ Coding Test Course, Cocktail Making - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:27:02+00:00\",\"dateModified\":\"2024-11-01T10:57:38+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34340\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/34340\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/34340\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C++ Coding Test Course, Cocktail Making\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C++ Coding Test Course, Cocktail Making - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/34340\/","og_locale":"ko_KR","og_type":"article","og_title":"C++ Coding Test Course, Cocktail Making - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"This course introduces how to solve the cocktail making problem using C++. Algorithmic problems generally require generating a desired output for a specific input. This problem involves making cocktails using various ingredients according to given proportions. Problem Description You want to make cocktails with various ingredients. Each ingredient requires a specific amount. You want to &hellip; \ub354 \ubcf4\uae30 \"C++ Coding Test Course, Cocktail Making\"","og_url":"https:\/\/atmokpo.com\/w\/34340\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:27:02+00:00","article_modified_time":"2024-11-01T10:57:38+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"3\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/34340\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/34340\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"C++ Coding Test Course, Cocktail Making","datePublished":"2024-11-01T09:27:02+00:00","dateModified":"2024-11-01T10:57:38+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/34340\/"},"wordCount":492,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["C++ Coding Test Tutorials"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/34340\/","url":"https:\/\/atmokpo.com\/w\/34340\/","name":"C++ Coding Test Course, Cocktail Making - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:27:02+00:00","dateModified":"2024-11-01T10:57:38+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/34340\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/34340\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/34340\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"C++ Coding Test Course, Cocktail Making"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34340","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=34340"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34340\/revisions"}],"predecessor-version":[{"id":34341,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34340\/revisions\/34341"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=34340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=34340"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=34340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}