From d2f829fa9b2b0ea3891ab18e15e7b597005e5c9b Mon Sep 17 00:00:00 2001 From: 6uohul Date: Mon, 18 Sep 2023 01:18:44 +0900 Subject: [PATCH] =?UTF-8?q?#9-=201463=20=EB=AC=B8=EC=A0=9C=20=ED=92=80?= =?UTF-8?q?=EC=9D=B4=201=EC=B0=A8=20=EC=8B=9C=EB=8F=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Algorithm/Algorithm.xcodeproj/project.pbxproj | 10 ++++--- Algorithm/Algorithm/BOJ/2751.swift | 21 +++++++++++++++ Algorithm/Algorithm/BOJ/main.swift | 27 ++++++++++++------- 3 files changed, 44 insertions(+), 14 deletions(-) create mode 100644 Algorithm/Algorithm/BOJ/2751.swift diff --git a/Algorithm/Algorithm.xcodeproj/project.pbxproj b/Algorithm/Algorithm.xcodeproj/project.pbxproj index 57ff253..6e806f3 100644 --- a/Algorithm/Algorithm.xcodeproj/project.pbxproj +++ b/Algorithm/Algorithm.xcodeproj/project.pbxproj @@ -7,7 +7,7 @@ objects = { /* Begin PBXBuildFile section */ - 1407E1402AB7121A00B4B4E6 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1407E13F2AB7121A00B4B4E6 /* main.swift */; }; + 1407E1422AB715CA00B4B4E6 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1407E1412AB715CA00B4B4E6 /* main.swift */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -27,7 +27,8 @@ 1407E10F2AAC384100B4B4E6 /* 2588.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = 2588.swift; sourceTree = ""; }; 1407E13B2AAE02CC00B4B4E6 /* 1152.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = 1152.swift; sourceTree = ""; }; 1407E13D2AB70A9600B4B4E6 /* 2163.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = 2163.swift; sourceTree = ""; }; - 1407E13F2AB7121A00B4B4E6 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; + 1407E13F2AB7121A00B4B4E6 /* 2751.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = 2751.swift; sourceTree = ""; }; + 1407E1412AB715CA00B4B4E6 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; 147A87B62AA07AF300C5FEFB /* Algorithm */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Algorithm; sourceTree = BUILT_PRODUCTS_DIR; }; 147A87B92AA07AF300C5FEFB /* 정수형_입력받기.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "정수형_입력받기.swift"; sourceTree = ""; }; 147A87C22AA0820E00C5FEFB /* 개행_단위_입력받기.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "개행_단위_입력받기.swift"; sourceTree = ""; }; @@ -89,7 +90,8 @@ 1407E10F2AAC384100B4B4E6 /* 2588.swift */, 1407E13B2AAE02CC00B4B4E6 /* 1152.swift */, 1407E13D2AB70A9600B4B4E6 /* 2163.swift */, - 1407E13F2AB7121A00B4B4E6 /* main.swift */, + 1407E13F2AB7121A00B4B4E6 /* 2751.swift */, + 1407E1412AB715CA00B4B4E6 /* main.swift */, ); path = BOJ; sourceTree = ""; @@ -153,7 +155,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 1407E1402AB7121A00B4B4E6 /* main.swift in Sources */, + 1407E1422AB715CA00B4B4E6 /* main.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Algorithm/Algorithm/BOJ/2751.swift b/Algorithm/Algorithm/BOJ/2751.swift new file mode 100644 index 0000000..427905c --- /dev/null +++ b/Algorithm/Algorithm/BOJ/2751.swift @@ -0,0 +1,21 @@ +// +// 2751.swift +// 수 정렬하기 2 +// +// Created by 김인영 on 2023/09/17. +// + +import Foundation + +let n = Int(readLine()!)! +var array = [Int]() + +for i in 0...n-1 { + array.append(Int(readLine()!)!) +} + +array.sort() + +for i in 0...n-1 { + print(array[i]) +} diff --git a/Algorithm/Algorithm/BOJ/main.swift b/Algorithm/Algorithm/BOJ/main.swift index 427905c..4cb6f41 100644 --- a/Algorithm/Algorithm/BOJ/main.swift +++ b/Algorithm/Algorithm/BOJ/main.swift @@ -1,21 +1,28 @@ // -// 2751.swift -// 수 정렬하기 2 +// 1463.swift +// 1로 만들기 // // Created by 김인영 on 2023/09/17. // import Foundation -let n = Int(readLine()!)! -var array = [Int]() +var input = Int(readLine()!)! +var count = 0 -for i in 0...n-1 { - array.append(Int(readLine()!)!) +func caculate(_ input: Int) -> Int { + if input % 3 == 0 { + return input / 3 + } else if input % 2 == 0 { + return input / 2 + } else { + return input - 1 + } } -array.sort() - -for i in 0...n-1 { - print(array[i]) +while input != 1 { + input = caculate(input) + count += 1 } + +print(count)