{"id":34120,"date":"2024-11-01T09:24:23","date_gmt":"2024-11-01T09:24:23","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=34120"},"modified":"2024-11-01T10:58:32","modified_gmt":"2024-11-01T10:58:32","slug":"c-coding-test-course-finding-good-numbers","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/34120\/","title":{"rendered":"C++ Coding Test Course, &#8216;Finding Good Numbers&#8217;"},"content":{"rendered":"<p><body><\/p>\n<h2>1. Introduction<\/h2>\n<p>\n        Solving algorithm problems is a very important factor in job preparation. Today, we will take a deep dive into the &#8216;good number&#8217; problem that many developers face. A &#8216;good number&#8217; refers to a number that meets certain conditions, and through this problem, you can enhance your thinking skills and improve your abilities.\n    <\/p>\n<h2>2. Problem Description<\/h2>\n<p>\n        You will receive an integer n as input. Among all the numbers less than or equal to n, we define a &#8216;good number&#8217; as a number whose sum of digits is less than or equal to 10.<br \/>\n        For example, 23 is a good number, but 24 is not because 2+4=6. The task is to find all &#8216;good numbers&#8217; less than or equal to the given n.\n    <\/p>\n<h3>2.1. Input<\/h3>\n<p>\n        An integer n (1 &lt;= n &lt;= 10000)\n    <\/p>\n<h3>2.2. Output<\/h3>\n<p>\n        Outputs the &#8216;good numbers&#8217; less than or equal to n.\n    <\/p>\n<h2>3. Approach<\/h2>\n<p>\n        To solve this problem, you can use the following approach.<\/p>\n<ul>\n<li>Iterate through numbers from 1 to n and separate each digit of the number.<\/li>\n<li>Calculate the sum of the digits.<\/li>\n<li>If the sum of the digits is less than or equal to 10, consider it a &#8216;good number&#8217; and print it.<\/li>\n<\/ul>\n<h3>3.1. Calculating the Sum of Digits<\/h3>\n<p>\n        To calculate the sum of the digits, you can use the method of dividing the number by 10 and obtaining the remainder. For example, when dividing 23, you get 3 (23 % 10) and 2 (23 \/ 10).<br \/>\n        By following this process, you can identify the digits of each number and calculate the sum.\n    <\/p>\n<h2>4. Code Implementation<\/h2>\n<p>\n        Now, let&#8217;s write C++ code based on the above approach. Below is the code for the program that finds &#8216;good numbers&#8217;.\n    <\/p>\n<pre><code>\n#include <iostream>\nusing namespace std;\n\nbool isGoodNumber(int number) {\n    int sum = 0;\n    while (number &gt; 0) {\n        sum += number % 10; \/\/ Adding the current digit\n        number \/= 10; \/\/ Calculating the next digit\n    }\n    return sum &lt;= 10; \/\/ Check if the sum of digits is less than or equal to 10\n}\n\nint main() {\n    int n;\n    cout &lt;&lt; \"Please enter an integer: \";\n    cin &gt;&gt; n;\n\n    cout &lt;&lt; \"Good numbers: \";\n    for (int i = 1; i &lt;= n; i++) {\n        if (isGoodNumber(i)) {\n            cout &lt;&lt; i &lt;&lt; \" \"; \/\/ Print good number\n        }\n    }\n    cout &lt;&lt; endl;\n    return 0;\n}\n    <\/iostream><\/code><\/pre>\n<h2>5. Code Explanation<\/h2>\n<p>\n        The above code is a simple program, consisting of the <code>isGoodNumber<\/code> function to determine &#8216;good numbers&#8217; and the main function <code>main<\/code>.\n    <\/p>\n<h3>5.1. isGoodNumber Function<\/h3>\n<p>\n        This function takes an integer as input, calculates the sum of its digits, and returns true or false based on the result.<br \/>\n        It uses a loop to separate and sum each digit of the number.\n    <\/p>\n<h3>5.2. Main Function<\/h3>\n<p>\n        In the main function, the user inputs n, and it checks numbers from 1 to n. It calls <code>isGoodNumber<\/code> for each number to determine if it is a good number.\n    <\/p>\n<h2>6. Time Complexity<\/h2>\n<p>\n        The time complexity of this algorithm is O(d * n), where d is the number of digits in n.<br \/>\n        Summing the digits for each number is performed at most 4 times, allowing it to handle larger n values in real-time.\n    <\/p>\n<h2>7. Optimization<\/h2>\n<p>\n        The current code may be inefficient as it considers all numbers and calculates the sum of digits.<br \/>\n        Instead, you can pre-calculate and store the sum of digits to reduce redundant calculations. Here is an example of code improvement for this.\n    <\/p>\n<pre><code>\n#include <iostream>\n#include <vector>\nusing namespace std;\n\nvector<int> precomputeGoodNumbers(int maxNum) {\n    vector<int> goodNumbers;\n    for (int i = 1; i &lt;= maxNum; i++) {\n        if (isGoodNumber(i)) {\n            goodNumbers.push_back(i); \/\/ Store good numbers\n        }\n    }\n    return goodNumbers;\n}\n\nint main() {\n    int n;\n    cout &lt;&lt; \"Please enter an integer: \";\n    cin &gt;&gt; n;\n\n    vector<int> goodNumbers = precomputeGoodNumbers(n);\n    cout &lt;&lt; \"Good numbers: \";\n    for (int number : goodNumbers) {\n        cout &lt;&lt; number &lt;&lt; \" \"; \/\/ Print pre-stored good numbers\n    }\n    cout &lt;&lt; endl;\n    return 0;\n}\n    <\/int><\/int><\/int><\/vector><\/iostream><\/code><\/pre>\n<h2>8. Conclusion<\/h2>\n<p>\n        Today, we explored the problem of finding &#8216;good numbers&#8217;. This problem is a great example of developing basic algorithmic thinking and improving problem-solving skills.<br \/>\n        Continue to strengthen your algorithmic skills through various problems. Happy coding!\n    <\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction Solving algorithm problems is a very important factor in job preparation. Today, we will take a deep dive into the &#8216;good number&#8217; problem that many developers face. A &#8216;good number&#8217; refers to a number that meets certain conditions, and through this problem, you can enhance your thinking skills and improve your abilities. 2. &hellip; <a href=\"https:\/\/atmokpo.com\/w\/34120\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;C++ Coding Test Course, &#8216;Finding Good Numbers&#8217;&#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-34120","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, &#039;Finding Good Numbers&#039; - \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\/34120\/\" \/>\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, &#039;Finding Good Numbers&#039; - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"1. Introduction Solving algorithm problems is a very important factor in job preparation. Today, we will take a deep dive into the &#8216;good number&#8217; problem that many developers face. A &#8216;good number&#8217; refers to a number that meets certain conditions, and through this problem, you can enhance your thinking skills and improve your abilities. 2. &hellip; \ub354 \ubcf4\uae30 &quot;C++ Coding Test Course, &#8216;Finding Good Numbers&#8217;&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/34120\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:24:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T10:58:32+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\/34120\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34120\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"C++ Coding Test Course, &#8216;Finding Good Numbers&#8217;\",\"datePublished\":\"2024-11-01T09:24:23+00:00\",\"dateModified\":\"2024-11-01T10:58:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34120\/\"},\"wordCount\":471,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"C++ Coding Test Tutorials\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/34120\/\",\"url\":\"https:\/\/atmokpo.com\/w\/34120\/\",\"name\":\"C++ Coding Test Course, 'Finding Good Numbers' - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:24:23+00:00\",\"dateModified\":\"2024-11-01T10:58:32+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34120\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/34120\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/34120\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C++ Coding Test Course, &#8216;Finding Good Numbers&#8217;\"}]},{\"@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, 'Finding Good Numbers' - \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\/34120\/","og_locale":"ko_KR","og_type":"article","og_title":"C++ Coding Test Course, 'Finding Good Numbers' - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"1. Introduction Solving algorithm problems is a very important factor in job preparation. Today, we will take a deep dive into the &#8216;good number&#8217; problem that many developers face. A &#8216;good number&#8217; refers to a number that meets certain conditions, and through this problem, you can enhance your thinking skills and improve your abilities. 2. &hellip; \ub354 \ubcf4\uae30 \"C++ Coding Test Course, &#8216;Finding Good Numbers&#8217;\"","og_url":"https:\/\/atmokpo.com\/w\/34120\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:24:23+00:00","article_modified_time":"2024-11-01T10:58:32+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\/34120\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/34120\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"C++ Coding Test Course, &#8216;Finding Good Numbers&#8217;","datePublished":"2024-11-01T09:24:23+00:00","dateModified":"2024-11-01T10:58:32+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/34120\/"},"wordCount":471,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["C++ Coding Test Tutorials"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/34120\/","url":"https:\/\/atmokpo.com\/w\/34120\/","name":"C++ Coding Test Course, 'Finding Good Numbers' - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:24:23+00:00","dateModified":"2024-11-01T10:58:32+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/34120\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/34120\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/34120\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"C++ Coding Test Course, &#8216;Finding Good Numbers&#8217;"}]},{"@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\/34120","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=34120"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34120\/revisions"}],"predecessor-version":[{"id":34121,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34120\/revisions\/34121"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=34120"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=34120"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=34120"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}