Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
See all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
devssun
Algorithm-Study
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
Algorithm-Study
/
Algorithm
/
baekjoon
/
1110_plus_cycle.swift
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
50 lines (41 loc) · 1.73 KB
master
Breadcrumbs
Algorithm-Study
/
Algorithm
/
baekjoon
/
1110_plus_cycle.swift
Copy path
Top
File metadata and controls
Code
Blame
50 lines (41 loc) · 1.73 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// https://www.acmicpc.net/problem/1110
// 뭔가 되게 지저분하고 복잡하지만.. 풀었다
import Foundation
func checkLimitNumber(_ input: Int) -> [Int] {
var result = [Int]()
// 3. 10 이하면 일의 자리에 0을 붙인다 / 이상이면 그대로 사용한다
if input < 10 {
result.append(0)
result.append(input)
}else{
result.append(input/10)
result.append(input%10)
}
return result
}
// 1. 숫자를 입력받는다
if let inputString = readLine(), let originNumber = Int(inputString) {
var count: Int = 1
// 2. 숫자가 10 이하인지 체크한다
var originNumbers = checkLimitNumber(originNumber)
// 8. 4번~8번을 반복하여 수행한다
while true {
// 4. 입력받은 숫자의 각 자리수의 숫자를 더한다
let result: [Int] = "\(originNumbers[0] + originNumbers[1])".compactMap {Int(String($0))}
print("더한 수 \(result)")
// 5. 주어진 수의 가장 오른쪽 자리 수와 앞에서 구한 합의 가장 오른쪽 자리 수를 이어 붙인다
var compareNumber = [Int]()
compareNumber.append(originNumbers.last!)
compareNumber.append(result.last!)
let compare = Int((compareNumber.map{String($0)}).joined())
// 6. 처음 입력 받은 숫자와 같은 지 체크한다
// 7. 같으면 사이클 수를 print 하고 종료한다 / 다르면 사이클 수 ++1 한다
print("값 체크 \(inputString) \(compareNumber)")
if originNumber == compare! {
print(count)
break
}
originNumbers = compare! < 10 ? checkLimitNumber(compare!) : compareNumber
count += 1
}
}
You can’t perform that action at this time.