๊ณต๋ถ€/๋ฐฑ์ค€ (Baekjoon)

[๋ฐฑ์ค€/ํŒŒ์ด์ฌ] 2857๋ฒˆ: FBI

eunjuu 2023. 9. 21. 16:21
728x90

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป ๋ฌธ์ œ

5๋ช…์˜ ์š”์› ์ค‘ FBI ์š”์›์„ ์ฐพ๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

FBI์š”์›์€ ์š”์›์˜ ์ฒฉ๋ณด์›๋ช…์— FBI๊ฐ€ ๋“ค์–ด์žˆ๋‹ค.

๐Ÿ“Ž https://www.acmicpc.net/problem/2857

 

2857๋ฒˆ: FBI

5๊ฐœ ์ค„์— ์š”์›์˜ ์ฒฉ๋ณด์›๋ช…์ด ์ฃผ์–ด์ง„๋‹ค. ์ฒฉ๋ณด์›๋ช…์€ ์•ŒํŒŒ๋ฒณ ๋Œ€๋ฌธ์ž, ์ˆซ์ž 0~9, ๋Œ€์‹œ (-)๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ์œผ๋ฉฐ, ์ตœ๋Œ€ 10๊ธ€์ž์ด๋‹ค.

www.acmicpc.net

 

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป ์ž…๋ ฅ

5๊ฐœ ์ค„์— ์š”์›์˜ ์ฒฉ๋ณด์›๋ช…์ด ์ฃผ์–ด์ง„๋‹ค. ์ฒฉ๋ณด์›๋ช…์€ ์•ŒํŒŒ๋ฒณ ๋Œ€๋ฌธ์ž, ์ˆซ์ž 0~9, ๋Œ€์‹œ (-)๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ์œผ๋ฉฐ, ์ตœ๋Œ€ 10๊ธ€์ž์ด๋‹ค.

 

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป ์ถœ๋ ฅ

์ฒซ์งธ ์ค„์— FBI ์š”์›์„ ์ถœ๋ ฅํ•œ๋‹ค. ์ด๋•Œ, ํ•ด๋‹นํ•˜๋Š” ์š”์›์ด ๋ช‡ ๋ฒˆ์งธ ์ž…๋ ฅ์ธ์ง€๋ฅผ ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„ํ•˜์—ฌ ์ถœ๋ ฅํ•ด์•ผ ํ•˜๋ฉฐ, ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ถœ๋ ฅํ•ด์•ผ ํ•œ๋‹ค. ๋งŒ์•ฝ FBI ์š”์›์ด ์—†๋‹ค๋ฉด "HE GOT AWAY!"๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

 

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป ์˜ˆ์ œ


๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป ์ฝ”๋“œ

list = []

for _ in range(5) :
  list.append(input())

flag = 0
for i in range(len(list)) :
  if 'FBI' in list[i] :
    print(i+1, end=' ')
    flag = 1

if flag == 0 :
  print('HE GOT AWAY!')

 

 

1. ์‚ฌ์šฉ์ž ์ž…๋ ฅ์„ ์ €์žฅํ•  ๋นˆ ๋ฆฌ์ŠคํŠธ list ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.

list = []

 

2. for ๋ฐ˜๋ณต๋ฌธ์„ ์‚ฌ์šฉํ•˜์—ฌ ์‚ฌ์šฉ์ž์˜ ์ž…๋ ฅ์„ 5๋ฒˆ ๋ฐ˜๋ณตํ•ด list ๋ฆฌ์ŠคํŠธ์— ์ถ”๊ฐ€ํ•œ๋‹ค. _ ๋Š” ๊ด€๋ก€์ ์œผ๋กœ ๋ฐ˜๋ณต ๋ณ€์ˆ˜์˜ ์ด๋ฆ„์œผ๋กœ ์‚ฌ์šฉ๋˜๋ฉฐ, ์—ฌ๊ธฐ์„œ๋Š” ๋ฐ˜๋ณต ํšŸ์ˆ˜๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ๋ณ€์ˆ˜๋‹ค.

for _ in range(5) :
  list.append(input())

 

3. flag ๋ณ€์ˆ˜๋ฅผ ์ดˆ๊ธฐํ™”ํ•˜๊ณ , ๋‚˜์ค‘์— ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก 0์œผ๋กœ ์„ค์ •ํ•œ๋‹ค. flag ๊ฐ’์ด ๊ณ„์† 0์ด๋ฉด ๋‚˜์ค‘์— FBI ์š”์›์ด ์—†๋‹ค๋Š” ๋ฌธ๊ตฌ๋ฅผ ์ถœ๋ ฅํ•  ๊ฒƒ์ด๋‹ค.

flag = 0

 

4. ์ฃผ์–ด์ง„ ๋ฆฌ์ŠคํŠธ์˜ ๊ฐ ์š”์†Œ๋ฅผ ์ธ๋ฑ์Šค i ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ˆœํšŒํ•œ๋‹ค. ๊ฐ ์š”์†Œ์—์„œ 'FBI' ๋ฌธ์ž์—ด์„ ๊ฒ€์‚ฌํ•˜๊ณ  ๋งŒ์•ฝ 'FBI' ๋ฌธ์ž์—ด์ด ํ•ด๋‹น ์š”์†Œ์— ํฌํ•จ๋˜์–ด ์žˆ๋‹ค๋ฉด, ํ•ด๋‹น ์š”์†Œ์˜ ์ธ๋ฑ์Šค ๋ฒˆํ˜ธ์— 1์„ ๋”ํ•œ ๊ฐ’์„ ์ถœ๋ ฅํ•˜๊ณ , flag ๋ณ€์ˆ˜๋ฅผ 1๋กœ ์„ค์ •ํ•œ๋‹ค.

for i in range(len(list)) :
  if 'FBI' in list[i] :
    print(i+1, end=' ')
    flag = 1

 

5. ์ด ๋ถ€๋ถ„์€ 'FBI'๊ฐ€ ๋ฐœ๊ฒฌ๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ์— ์‹คํ–‰๋˜๋ฉฐ, "HE GOT AWAY!"๋ผ๋Š” ๋ฉ”์‹œ์ง€๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. ์ฆ‰, 'FBI' ์š”์›์ด ํ•˜๋‚˜๋„ ๋ฐœ๊ฒฌ๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ์— ํ•ด๋‹น ๋ฉ”์‹œ์ง€๊ฐ€ ์ถœ๋ ฅ๋œ๋‹ค.

if flag == 0 :
  print('HE GOT AWAY!')

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป ์ •๋‹ต ์ œ์ถœ

FBI-0909, KFBI-1010
HE GOT AWAY!

728x90