Skip to content

Commit 94e69d1

Browse files
committed
#7 - 가운데 글자 가져오기 문제 풀이
1 parent 957f0df commit 94e69d1

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

Diff for: ProgrammersLevel1/ProgrammersLevel1.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
3341499A2897EA4D008BB719 /* otherSolve.swift in Sources */ = {isa = PBXBuildFile; fileRef = 334149992897EA4D008BB719 /* otherSolve.swift */; };
1313
33DFAE3C2898036B0075DD46 /* 신규 아이디 추천.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33DFAE3B2898036A0075DD46 /* 신규 아이디 추천.swift */; };
1414
33DFAE3E28980C360075DD46 /* 키패드 누르기.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33DFAE3D28980C360075DD46 /* 키패드 누르기.swift */; };
15+
33DFAE40289814930075DD46 /* 가운데 글자 가져오기.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33DFAE3F289814930075DD46 /* 가운데 글자 가져오기.swift */; };
1516
/* End PBXBuildFile section */
1617

1718
/* Begin PBXCopyFilesBuildPhase section */
@@ -33,6 +34,7 @@
3334
334149992897EA4D008BB719 /* otherSolve.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = otherSolve.swift; sourceTree = "<group>"; };
3435
33DFAE3B2898036A0075DD46 /* 신규 아이디 추천.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "신규 아이디 추천.swift"; sourceTree = "<group>"; };
3536
33DFAE3D28980C360075DD46 /* 키패드 누르기.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "키패드 누르기.swift"; sourceTree = "<group>"; };
37+
33DFAE3F289814930075DD46 /* 가운데 글자 가져오기.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "가운데 글자 가져오기.swift"; sourceTree = "<group>"; };
3638
/* End PBXFileReference section */
3739

3840
/* Begin PBXFrameworksBuildPhase section */
@@ -69,6 +71,7 @@
6971
334149962897E910008BB719 /* 7-NoneNumberPlus */,
7072
3341498F2897E853008BB719 /* main.swift */,
7173
33DFAE3D28980C360075DD46 /* 키패드 누르기.swift */,
74+
33DFAE3F289814930075DD46 /* 가운데 글자 가져오기.swift */,
7275
);
7376
path = ProgrammersLevel1;
7477
sourceTree = "<group>";
@@ -143,6 +146,7 @@
143146
33DFAE3C2898036B0075DD46 /* 신규 아이디 추천.swift in Sources */,
144147
33DFAE3E28980C360075DD46 /* 키패드 누르기.swift in Sources */,
145148
334149902897E853008BB719 /* main.swift in Sources */,
149+
33DFAE40289814930075DD46 /* 가운데 글자 가져오기.swift in Sources */,
146150
3341499A2897EA4D008BB719 /* otherSolve.swift in Sources */,
147151
334149982897E948008BB719 /* solve.swift in Sources */,
148152
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// 가운데 글자 가져오기.swift
3+
// ProgrammersLevel1
4+
//
5+
// Created by hwangJi on 2022/08/01.
6+
//
7+
8+
import Foundation
9+
10+
func solutions1(_ s:String) -> String {
11+
12+
if s.count % 2 == 0 {
13+
let index = s.index(s.startIndex, offsetBy: s.count / 2 - 1)..<s.index(s.startIndex, offsetBy: s.count / 2 + 1)
14+
return String(describing: s[index])
15+
} else {
16+
let index = s.index(s.startIndex, offsetBy: s.count / 2)
17+
return String(describing: s[index])
18+
}
19+
}
20+
21+
func solutions2(_ s:String) -> String {
22+
return String(s[String.Index(utf16Offset: (s.count - 1) / 2, in: s)...String.Index(utf16Offset: s.count / 2, in: s)])
23+
}

0 commit comments

Comments
 (0)