๋ฌธ์ :
https://www.acmicpc.net/problem/20361
๋ถ์ :
๊ตฌ์ฌ์ด ์๋ ์์น๋ฅผ true๋ก ํ๋ ๋ฐฐ์ด์ ๋ง๋ค๊น ํ๋ค๊ฐ ์์น๋ฅผ ๋ณ์๋ก ์ ๋ฐ์ดํธ ํด์ค์ ์์ ๊ฑฐ ๊ฐ์์
๋ฐฐ์ด์ ์์ฐ๊ณ ํ์๋ค !
Swift ์ฝ๋ :
//
// main.swift
// SOMA๐ฉ๐ป๐ป
//
// Created by JoSoJeong on 2022/04/12.
//
import Foundation
var line = readLine()!.split(separator: " ").map { Int(String($0))! }
var n = line[0]
var x = line[1]
var k = line[2]
var answer = x
for _ in 0..<k {
var line = readLine()!.split(separator: " ").map { Int(String($0))! }
var l1 = line[0]
var l2 = line[1]
if(l1 == answer){
answer = l2
}else if(l2 == answer) {
answer = l1
}
}
print(answer)
'Algorithm๐ฐ > ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค] Swift 1309 ๋๋ฌผ์ DP (0) | 2022.04.16 |
---|---|
[๋ฐฑ์ค] 1049 Swift ๊ธฐํ์ค Greedy (0) | 2022.04.13 |
[๋ฐฑ์ค] Swift 9466 ํ ํ๋ก์ ํธ DFS (0) | 2022.04.12 |
[๋ฐฑ์ค] Swift 2529 ๋ถ๋ฑํธ backtracking (0) | 2022.04.07 |
[๋ฐฑ์ค] Swift 1300 k๋ฒ์งธ ์ BS(Bineary Search) (0) | 2022.03.31 |
๋๊ธ