{"id":34696,"date":"2024-11-01T09:30:58","date_gmt":"2024-11-01T09:30:58","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=34696"},"modified":"2024-11-01T11:26:57","modified_gmt":"2024-11-01T11:26:57","slug":"swift-coding-test-course-exploring-geometry","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/34696\/","title":{"rendered":"Swift Coding Test Course, Exploring Geometry"},"content":{"rendered":"<p><body><\/p>\n<header>\n<\/header>\n<section>\n<h2>Introduction<\/h2>\n<p>Hello! In this tutorial, we will learn how to solve geometric algorithm problems using Swift. Geometric problems are one of the frequently asked topics in coding tests, and the ability to solve problems related to points, lines, and surfaces in a coordinate system is crucial. In this article, we will present fundamental concepts of geometry, along with algorithmic problems that utilize these concepts, and we will explain the process of solving those problems in detail.<\/p>\n<\/section>\n<section>\n<h2>Basics of Geometry<\/h2>\n<p>Geometry is a branch of mathematics that studies shapes and the relationships between those shapes. The geometric objects mainly dealt with in algorithm problems include points, lines, triangles, and polygons. Various problems can be solved by utilizing the properties of these geometric figures. For example, calculating the distance between two points, whether lines intersect, and determining the perimeter and area of polygons are key aspects of geometric problems.<\/p>\n<\/section>\n<section>\n<h2>Problem Description<\/h2>\n<p>The problem at hand is to calculate the area of a polygon. You will need to write an algorithm that calculates the area of a polygon formed by connecting N given points.<\/p>\n<h3>Problem<\/h3>\n<p>Given N points, write an algorithm to calculate the area of the polygon formed by connecting these points. The points are provided in a two-dimensional plane, and their coordinates are expressed as integers.<\/p>\n<h3>Input<\/h3>\n<ul>\n<li>The first line contains an integer N (3 \u2264 N \u2264 10^6).<\/li>\n<li>In the next N lines, the X and Y coordinates of each point are given as integers.<\/li>\n<\/ul>\n<h3>Output<\/h3>\n<p>Print the area of the polygon rounded to the second decimal place.<\/p>\n<\/section>\n<section>\n<h2>Problem Solving Process<\/h2>\n<p>To design an algorithm for solving the problem, one must first understand how to calculate the area of a polygon. Generally, the most widely known method for calculating the area of a polygon is the &#8216;Shoelace Theorem&#8217; (or &#8216;Surveyor&#8217;s Formula&#8217;). This method uses the following formula:<\/p>\n<h3>Shoelace Theorem<\/h3>\n<p>Given points (x<sub>1<\/sub>, y<sub>1<\/sub>), (x<sub>2<\/sub>, y<sub>2<\/sub>), &#8230;, (x<sub>N<\/sub>, y<sub>N<\/sub>), the area of the polygon can be calculated as follows:<\/p>\n<p><math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\">\n<mrow>\n<mo>=<\/mo>\n<mfrac>\n<mrow>\n<mo>(<\/mo>\n<mstyle displaystyle=\"true\">\n<mo>\u2211<\/mo>\n<\/mstyle>\n<mrow>\n<mo>(<\/mo>\n<mrow>\n<mi>x<\/mi>\n<mo>_<\/mo>\n<mi>i<\/mi>\n<\/mrow>\n<mo>\u00b7<\/mo>\n<mrow>\n<mi>y<\/mi>\n<mo>_<\/mo>\n<mi>i+1<\/mi>\n<\/mrow>\n<mo>)<\/mo>\n<\/mrow>\n<mo>&#8211;<\/mo>\n<mstyle displaystyle=\"true\">\n<mo>\u2211<\/mo>\n<\/mstyle>\n<mrow>\n<mo>(<\/mo>\n<mrow>\n<mi>y<\/mi>\n<mo>_<\/mo>\n<mi>i<\/mi>\n<\/mrow>\n<mo>\u00b7<\/mo>\n<mrow>\n<mi>x<\/mi>\n<mo>_<\/mo>\n<mi>i+1<\/mi>\n<\/mrow>\n<mo>)<\/mo>\n<\/mrow>\n<mo>)<\/mo>\n<\/mrow>\n<mn>2<\/mn>\n<\/mfrac>\n<\/mrow>\n<\/math><\/p>\n<p>To put this very simply, you take the absolute value of the sum obtained by applying the above formula to all the points of the polygon, and divide by 2 to get the area. Now, let\u2019s implement this in Swift.<\/p>\n<\/section>\n<section>\n<h2>Swift Implementation<\/h2>\n<pre>\n            <code>\n                import Foundation\n\n                struct Point {\n                    var x: Int\n                    var y: Int\n                }\n\n                func polygonArea(points: [Point]) -> Double {\n                    var area = 0\n                    let n = points.count\n\n                    for i in 0..<n {\n                        let j = (i + 1) % n\n                        area += Double(points[i].x * points[j].y) - Double(points[j].x * points[i].y)\n                    }\n                    return abs(area) \/ 2.0\n                }\n\n                func main() {\n                    let n = Int(readLine()!)!\n                    var points: [Point] = []\n\n                    for _ in 0..<n {\n                        let coordinates = readLine()!.split(separator: \" \")\n                        let point = Point(x: Int(coordinates[0])!, y: Int(coordinates[1])!)\n                        points.append(point)\n                    }\n                    print(String(format: \"%.2f\", polygonArea(points: points)))\n                }\n            <\/code>\n<\/pre>\n<p>With the above code, we have implemented the functionality to calculate the area of a polygon. We use structs to represent the coordinates of the points, and the polygonArea function calculates the area for the given list of points. Finally, we handle the input of these points and output the area in the main function.<\/p>\n<\/section>\n<section>\n<h2>Conclusion<\/h2>\n<p>Through this tutorial, we have learned about geometric problems and the algorithms for solving them. We wrote a program to calculate the area of a polygon using Swift, which is a very useful technique in coding tests. There are various variations of geometric problems, so it is important to have a thorough understanding of the basic concepts and to practice. Keep challenging yourself with various geometric problems to build your skills!<\/p>\n<\/section>\n<footer>\n<p>\u00a9 2023 Swift Coding Test Course<\/p>\n<\/footer>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Hello! In this tutorial, we will learn how to solve geometric algorithm problems using Swift. Geometric problems are one of the frequently asked topics in coding tests, and the ability to solve problems related to points, lines, and surfaces in a coordinate system is crucial. In this article, we will present fundamental concepts of &hellip; <a href=\"https:\/\/atmokpo.com\/w\/34696\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Swift Coding Test Course, Exploring Geometry&#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":[129],"tags":[],"class_list":["post-34696","post","type-post","status-publish","format-standard","hentry","category-swift-coding-test"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Swift Coding Test Course, Exploring Geometry - \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\/34696\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Swift Coding Test Course, Exploring Geometry - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Introduction Hello! In this tutorial, we will learn how to solve geometric algorithm problems using Swift. Geometric problems are one of the frequently asked topics in coding tests, and the ability to solve problems related to points, lines, and surfaces in a coordinate system is crucial. In this article, we will present fundamental concepts of &hellip; \ub354 \ubcf4\uae30 &quot;Swift Coding Test Course, Exploring Geometry&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/34696\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:30:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:26:57+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=\"2\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/34696\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34696\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Swift Coding Test Course, Exploring Geometry\",\"datePublished\":\"2024-11-01T09:30:58+00:00\",\"dateModified\":\"2024-11-01T11:26:57+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34696\/\"},\"wordCount\":512,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Swift Coding Test\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/34696\/\",\"url\":\"https:\/\/atmokpo.com\/w\/34696\/\",\"name\":\"Swift Coding Test Course, Exploring Geometry - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:30:58+00:00\",\"dateModified\":\"2024-11-01T11:26:57+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34696\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/34696\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/34696\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Swift Coding Test Course, Exploring Geometry\"}]},{\"@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":"Swift Coding Test Course, Exploring Geometry - \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\/34696\/","og_locale":"ko_KR","og_type":"article","og_title":"Swift Coding Test Course, Exploring Geometry - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Introduction Hello! In this tutorial, we will learn how to solve geometric algorithm problems using Swift. Geometric problems are one of the frequently asked topics in coding tests, and the ability to solve problems related to points, lines, and surfaces in a coordinate system is crucial. In this article, we will present fundamental concepts of &hellip; \ub354 \ubcf4\uae30 \"Swift Coding Test Course, Exploring Geometry\"","og_url":"https:\/\/atmokpo.com\/w\/34696\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:30:58+00:00","article_modified_time":"2024-11-01T11:26:57+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":"2\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/34696\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/34696\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Swift Coding Test Course, Exploring Geometry","datePublished":"2024-11-01T09:30:58+00:00","dateModified":"2024-11-01T11:26:57+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/34696\/"},"wordCount":512,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Swift Coding Test"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/34696\/","url":"https:\/\/atmokpo.com\/w\/34696\/","name":"Swift Coding Test Course, Exploring Geometry - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:30:58+00:00","dateModified":"2024-11-01T11:26:57+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/34696\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/34696\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/34696\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Swift Coding Test Course, Exploring Geometry"}]},{"@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\/34696","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=34696"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34696\/revisions"}],"predecessor-version":[{"id":34697,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34696\/revisions\/34697"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=34696"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=34696"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=34696"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}