๋ฐ์ํ
๋ฌธ์ ๋งํฌ
https://www.acmicpc.net/problem/11655
๋ด๊ฐ ํผ ํ์ด (1) - ๋ฐํ์ ์๋ฌ
- ๋ฐฐ์ด ๋๊ฐ๋ฅผ ์ฌ์ฉํด์ 26๋ฌธ์ 26๋ฌธ์๋ฅผ ๋ฃ์๊น ํ๋ค๊ฐ dic์ด ๋ฉ๋ชจ๋ฆฌ๊ฐ ๋ ์ ์๊ฒ(?)์ ์๊ณ dic์ผ๋ก ๊ตฌ์ฑํ๋ค.
- ์๋ฌด๋๋ ๋ชจ๋ ๋ฌธ์๋ฅผ dic์ ๋ฃ๋ ๊ฒ์ด๋ค ๋ณด๋, ๋ฐํ์์๋ฌ๊ฐ ๋ฐ์ํ๋ ๊ฒ ๊ฐ๋ค.
let line = Array(readLine()!)
var answer: [Character] = []
let dic: [String:Character] = ["a":"n", "b":"o", "c":"p", "d":"q", "e":"r", "f":"s", "g":"t", "h":"u",
"i":"v", "j":"w", "k":"x", "l":"y", "m":"z", "n":"a","o":"b", "p":"c", "q":"d",
"r":"e", "s":"f", "t":"g", "u":"h", "v":"i", "w":"j", "x":"k", "y":"l", "z":"m",]
for l in line {
if l.asciiValue! >= 65 && l.asciiValue! <= 90 {
answer.append(Character(dic[String(l.lowercased())]!.uppercased()))
} else {
answer.append(dic[String(l)]!)
}
}
print(answer.map { "\($0)"}.joined(separator: ""))
๋ด๊ฐ ํผ ํ์ด (2) - ๋ง์์ต๋๋ค!
- ๊ทธ๋ฅ ์ ๋ ฅ๋ฐ์ line ์ ํ๊ธ์์ฉ ascii ๊ฐ์ผ๋ก ๋ฐ๊พธ์ด์ ํ์๋ค.
- ์ค์ํํธ๋ง๊ณ ํ์ด์ฌ์ผ๋ก ํผ ํ์ด๋ฅผ ์ฐพ์๋ณด์๋๋ฐ, ๊ฑฐ๊ธฐ์ ํด๋ต(ํํธ)๋ฅผ ์ป์๋ค.
- ์ด๋ ๊ฒ dic๊ณผ ๋ฐฐ์ด์ ๋ง์ ๋ฌธ์๋ฅผ ๋ฃ์ด์ผํ๋ ๊ฒฝ์ฐ์๋, ascii๋ฅผ ์ด์ฉํด์ผ๊ฒ ๋ค.
let line = readLine()!
var answer = ""
for ch in line {
var rot13 = ch.asciiValue!
if rot13 >= 65 && rot13 <= 90 {
rot13 += 13
if rot13 > 90 {
rot13 -= 26
}
} else if rot13 >= 97 && rot13 <= 122 {
rot13 += 13
if rot13 > 122 {
rot13 -= 26
}
}
answer += "\(UnicodeScalar(rot13))"
}
print(answer)
์ ๊ทผ๋ฐ, ์๊ฐ๋ณต์ก๋์ ๋ํ ๊ฐ๋ ์ ์์ง๋ง, ์ฝ๋๋ณ๋ก ์ด๋ป๊ฒ ๊ณ์ฐํ๋ ๊ฒ์ผ๊น? ๊ธฐ๋ณธ์ ์ธ ์๊ณ ๋ฆฌ์ฆ/์๋ฃ๊ตฌ์กฐ ์์ ์ ๋ฃ์ง ์์์ ๋ชจ๋ฅด๊ฒ ๋ค. ๋ฌด์งํ ๋ถ๋ถ์ด ์ฐธ๋ง๋ค ใ ใ ์ด๊ฑฐ ์์๋ณด์.
๋ฐ์ํ
'Algorithm > Baekjoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค] (Swift) 11656๋ฒ - ์ ๋ฏธ์ฌ ๋ฐฐ์ด (0) | 2022.02.19 |
---|---|
[๋ฐฑ์ค] (Swift) 10824๋ฒ - ๋ค ์ (0) | 2022.02.18 |
[๋ฐฑ์ค] (Swift) 10820๋ฒ - ๋ฌธ์์ด ๋ถ์ (0) | 2022.02.16 |
[๋ฐฑ์ค] (Swift) 2743๋ฒ - ๋จ์ด ๊ธธ์ด ์ ๊ธฐ (0) | 2022.02.16 |
[๋ฐฑ์ค] (Swift) 10809๋ฒ - ์ํ๋ฒณ ์ฐพ๊ธฐ (0) | 2022.02.15 |