Bibi's DevLog ๐Ÿค“๐ŸŽ

[๋ฐฑ์ค€ 16171] ๋‚˜๋Š” ์นœ๊ตฌ๊ฐ€ ์ ๋‹ค(Small) (Swift) ๋ณธ๋ฌธ

ํ”„๋กœ๊ทธ๋ž˜๋ฐ/์•Œ๊ณ ๋ฆฌ์ฆ˜ ํ’€์ด Swift

[๋ฐฑ์ค€ 16171] ๋‚˜๋Š” ์นœ๊ตฌ๊ฐ€ ์ ๋‹ค(Small) (Swift)

๋น„๋น„ bibi 2023. 2. 15. 12:23

16171๋ฒˆ: ๋‚˜๋Š” ์นœ๊ตฌ๊ฐ€ ์ ๋‹ค (Small)

๋ฌธ์ž์—ด S์™€ ๋ฌธ์ž์—ด K๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ, S์—์„œ ์ˆซ์ž๋“ค์„ ๊ฑธ๋Ÿฌ๋‚ธ ๊ฒฐ๊ณผ์— K๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๋Š” ๋ฌธ์ œ์ด๋‹ค.

์žˆ์œผ๋ฉด 1, ์—†์œผ๋ฉด 0์„ ์ถœ๋ ฅํ•œ๋‹ค.

ํ’€์ด

import Foundation

let input = readLine()!
let keyword = readLine()!
let filteredInput = input.filter { $0.isLetter }
filteredInput.contains(keyword) ? print(1) : print(0)
  • filter๋กœ isLetter์ธ์ง€ ํ™•์ธ ํ›„ ๋ฌธ์ž๋งŒ ๊ฑธ๋Ÿฌ๋‚ธ๋‹ค.
  • contains๋กœ ํ‚ค์›Œ๋“œ๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธํ•œ๋‹ค.

์ด ํ’€์ด์—์„œ ์œ ์˜ํ•  ์ ์€ import Foundation์ด ์—†์œผ๋ฉด ์ปดํŒŒ์ผ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.

์•„์ง ์ด์œ ๋Š” ์ฐพ์ง€ ๋ชปํ–ˆ๋‹ค.. filter, contains ๋ชจ๋‘ Foundation์ด ์—†์–ด๋„ ์“ธ ์ˆ˜ ์žˆ๊ณ , ๋ฐฑ์ค€์˜ ์ฑ„์  ํ™˜๊ฒฝ๋„ Swift 5.5์ด์ƒ์ด๊ณ , Xcode์—์„œ๋Š” ๋™์ผํ•œ ์ฝ”๋“œ๋กœ ์‹คํ–‰ํ–ˆ์„ ๋•Œ ๊ฐ™์€ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜์ง€ ์•Š๋Š”๋ฐ, ์™œ โ€˜ํ‹€๋ ธ์Šต๋‹ˆ๋‹คโ€™ ๋„ ์•„๋‹ˆ๊ณ  ์ปดํŒŒ์ผ์—๋Ÿฌ๊ฐ€ ๋‚˜๋Š”์ง€ ํ ๐Ÿค” .. ํ˜น์‹œ ์ด์œ  ์•„์‹œ๋Š” ๋ถ„์€ ์ œ๋ณด ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค!

https://user-images.githubusercontent.com/67407678/218918939-d1dd739f-c097-46bb-be5c-956a08f6f585.png