1. ๋ฌธ์
2. ์ ์ถ๋ ฅ
3. ์ ์ถ๋ ฅ ์์
4. ๋ฌธ์ ์ค๊ณ
- ๊ธด ๋ฌธ์์ด์ ๊ธฐ์ค์ผ๋ก ๊ฐ๋ น, watermelon์ธ ๊ฒฝ์ฐ index๋ฅผ 0~4, 1 ~ 5, 2 ~ 6, 3 ~ 7, 4 ~ 8, 5 ~ 9 ํจํด์ผ๋ก ์ํํ๊ณ ,
- ์งง์ ๋ฌธ์์ด์ ๊ธฐ์ค์ผ๋ก ๊ฐ๋ น, melon์ธ ๊ฒฝ์ฐ ์ index์์์ ์ ์ฒด๋ฅผ ์ํํ๋ฉด์ ๊ฐ์ ๊ฐ์๊ฐ ์งง์ ๋ฌธ์์ด ๊ธธ์ด์ ๊ฐ๋ค๋ฉด,
- ๊ธด ๋ฌธ์์ด์ ์งง์ ๋ฌธ์์ด์ด ํฌํจ๋จ์ ์ ์ ์์
5. ์ ์ฒด ์ฝ๋
//
// main.swift
// IncludeString
//
// Created by ์ด์์ฌ on 2022/03/10.
//MARK: - ๋ฌธ์์ด ํฌํจ๊ด๊ณ ์กฐ์ฌ
//MARK: - Framework
import Foundation
//MARK: - Function
func solution() -> Void {
//MARK: - Input
guard let A: String = readLine() else { return }
guard let B: String = readLine() else { return }
var flag: Bool = false
//MARK: - Process
if A.count < B.count {
flag = false
} else {
for i in 0...A.count - B.count {
var sameCount: Int = 0
for j in 0..<B.count {
sameCount += B[B.index(B.startIndex, offsetBy: j)] == A[A.index(A.startIndex, offsetBy: i + j)] ? 1 : 0
}
if sameCount == B.count {
flag = true
break
}
}
}
//MARK: - Output
print(flag ? "YES" : "NO")
}
solution()
์ ์ฒด์ฝ๋๋ ์ฌ๊ธฐ์์ ํ์ธํ ์ ์์ต๋๋ค.
'Swift Data Structure And Algorithm > String Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๋ฌธ์์ด ์ ๋ ฌ (0) | 2022.03.10 |
---|---|
ํฐ ์๋ฆฟ์ ๊ณฑ์ (0) | 2022.03.10 |
ํฐ ์๋ฆฟ์ ๋บ์ (0) | 2022.03.10 |
ํฐ ์๋ฆฟ์ ๋ง์ (0) | 2022.03.10 |
๋ฌธ์์ด ์์ถ (0) | 2022.03.10 |