Bibi's DevLog ๐ค๐
[๋ฐฑ์ค 9076] ์ ์ ์ง๊ณ (Swift) ๋ณธ๋ฌธ
ํ๋ก๊ทธ๋๋ฐ/์๊ณ ๋ฆฌ์ฆ ํ์ด Swift
[๋ฐฑ์ค 9076] ์ ์ ์ง๊ณ (Swift)
๋น๋น bibi 2022. 12. 6. 12:38- ํ์ด ์์ฒด๋ ์ด๋ ต์ง ์์ผ๋, ArraySlice(SubSequence)์ ๋ํด ์๊ฒ ๋ ๋ฌธ์ .
- ArraySlice์ ๋ํ ๊ธ์ ์ฌ๊ธฐ์ ๋ฐ๋ก ์์ฑํ์ต๋๋ค.
ํ์ด
let count = Int(readLine()!)!
(1...count).forEach { num in
let inputArr = readLine()!.split(separator: " ").map { Int($0)! }.sorted()
let newArr = Array<Int>(inputArr[1...3]) // ์ ๋ฐฐ์ด์ ๋ง๋ค์ด ์ฌ์ฉ
if newArr[2] - newArr[0] >= 4 {
print("KIN")
} else {
print(newArr.reduce(0, +))
}
}
let count = Int(readLine()!)!
(1...count).forEach { num in
let inputArr = readLine()!.split(separator: " ").map { Int($0)! }.sorted()
let newArr = inputArr[1...3] // ArraySlice ์ฌ์ฉ
if newArr[3] - newArr[1] >= 4 {
print("KIN")
} else {
print(newArr.reduce(0, +))
}
}
ํ์ง๋ง ์๊ฐํด ๋ณด๋.. ์ฌ์ค sorted()๋ฅผ ํ๊ธฐ ๋๋ฌธ์ ์ ๋ฐฐ์ด์ ๋ง๋ค ํ์๊ฐ ์์๋ค..!
let count = Int(readLine()!)!
(1...count).forEach { num in
let inputArr = readLine()!.split(separator: " ").map { Int($0)! }.sorted()
if inputArr[3] - inputArr[1] >= 4 {
print("KIN")
} else {
print(inputArr[1...3].reduce(0, +))
}
}
'ํ๋ก๊ทธ๋๋ฐ > ์๊ณ ๋ฆฌ์ฆ ํ์ด Swift' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค 9469, 14924] ํฐ ๋ ธ์ด๋ง, ํฐ ๋ ธ์ด๋ง๊ณผ ํ๋ฆฌ (Swift) (0) | 2022.12.09 |
---|---|
[๋ฐฑ์ค 9094] ์ํ์ ํธ๊ธฐ์ฌ (Swift) (0) | 2022.12.07 |
[๋ฐฑ์ค 7510] ๊ณ ๊ธ ์ํ (Swift) (0) | 2022.11.29 |
[๋ฐฑ์ค 6376] e ๊ณ์ฐ (Swift) (0) | 2022.11.28 |
[๋ฐฑ์ค 6359] ๋ง์ทจํ ์๋ฒ (Swift) (0) | 2022.11.23 |