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

[๋ฐฑ์ค€/ํŒŒ์ด์ฌ] 1264๋ฒˆ: ๋ชจ์Œ์˜ ๊ฐœ์ˆ˜

eunjuu 2023. 9. 7. 13:51
728x90

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

์˜๋ฌธ ๋ฌธ์žฅ์„ ์ž…๋ ฅ๋ฐ›์•„ ๋ชจ์Œ์˜ ๊ฐœ์ˆ˜๋ฅผ ์„ธ๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ๋ชจ์Œ์€ 'a', 'e', 'i', 'o', 'u'์ด๋ฉฐ ๋Œ€๋ฌธ์ž ๋˜๋Š” ์†Œ๋ฌธ์ž์ด๋‹ค.

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

 

1264๋ฒˆ: ๋ชจ์Œ์˜ ๊ฐœ์ˆ˜

์ž…๋ ฅ์€ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์œผ๋ฉฐ, ๊ฐ ์ค„๋งˆ๋‹ค ์˜์–ด ๋Œ€์†Œ๋ฌธ์ž, ',', '.', '!', '?', ๊ณต๋ฐฑ์œผ๋กœ ์ด๋ฃจ์–ด์ง„ ๋ฌธ์žฅ์ด ์ฃผ์–ด์ง„๋‹ค. ๊ฐ ์ค„์€ ์ตœ๋Œ€ 255๊ธ€์ž๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค. ์ž…๋ ฅ์˜ ๋์—๋Š” ํ•œ ์ค„

www.acmicpc.net

 

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

์ž…๋ ฅ์€ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์œผ๋ฉฐ, ๊ฐ ์ค„๋งˆ๋‹ค ์˜์–ด ๋Œ€์†Œ๋ฌธ์ž, ',', '.', '!', '?', ๊ณต๋ฐฑ์œผ๋กœ ์ด๋ฃจ์–ด์ง„ ๋ฌธ์žฅ์ด ์ฃผ์–ด์ง„๋‹ค. ๊ฐ ์ค„์€ ์ตœ๋Œ€ 255๊ธ€์ž๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค.

์ž…๋ ฅ์˜ ๋์—๋Š” ํ•œ ์ค„์— '#' ํ•œ ๊ธ€์ž๋งŒ์ด ์ฃผ์–ด์ง„๋‹ค.

 

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

๊ฐ ์ค„๋งˆ๋‹ค ๋ชจ์Œ์˜ ๊ฐœ์ˆ˜๋ฅผ ์„ธ์„œ ์ถœ๋ ฅํ•œ๋‹ค.

 

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


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

vowels = ['a', 'e', 'i', 'o', 'u']

while True:
    count = 0
    sentence = input()
    if sentence == '#':
        break
    for i in sentence.lower():
        if i in vowels:
            count += 1
    print(count)

 

1. ๋ชจ์Œ ๋ฆฌ์ŠคํŠธ "vowels"๋ฅผ ์„ ์–ธํ•œ๋‹ค.

vowels = ['a', 'e', 'i', 'o', 'u']

 

2. ๋ฌดํ•œ ๋ฃจํ”„๋ฅผ ํ†ตํ•ด ์ƒˆ ๋ฌธ์žฅ์„ ์ž…๋ ฅ๋ฐ›์„ ๋•Œ๋งˆ๋‹ค, ๊ฐ ๋ฌธ์žฅ์˜ count ๊ฐœ์ˆ˜๊ฐ€ 0์ธ ์ƒํƒœ๋กœ ์‹œ์ž‘ํ•ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— count๋ฅผ ์ดˆ๊ธฐํ™”ํ•œ๋‹ค. ๊ทธ ํ›„ input() ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•ด ๋ฌธ์žฅ์„ ๋ฐ›๋Š”๋‹ค.

while True:
    count = 0
    sentence = input()

 

3. if break ๋ฌธ์„ ํ†ตํ•ด '#'์„ ์ž…๋ ฅ๋ฐ›์œผ๋ฉด ์ž…๋ ฅ์„ ๋ฉˆ์ถ”๋„๋ก ์„ค๊ณ„ํ•œ๋‹ค.

while True:
    count = 0
    sentence = input()
    if sentence == '#':
        break

 

4. lower() ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•ด sentence ์ „์ฒด๋ฅผ ์†Œ๋ฌธ์ž๋กœ ๋ฐ”๊พธ๊ณ , for in ๋ฌธ์„ ํ†ตํ•ด ์†Œ๋ฌธ์žํ™”๋œ sentence ์•ˆ์˜ ๋ฌธ์ž๋“ค์„ ํ•˜๋‚˜์”ฉ ๋ฝ‘์•„ i์— ์ €์žฅํ•œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  if in๋ฌธ์„ ํ†ตํ•ด i๊ฐ€ vowels ๋ฆฌ์ŠคํŠธ์— ๋‹ด๊ฒจ์žˆ์„ ๊ฒฝ์šฐ(๋ชจ์Œ์ผ ๊ฒฝ์šฐ) count๋ฅผ 1์”ฉ ์ฆ๊ฐ€์‹œ์ผœ ๊ฐœ์ˆ˜๋ฅผ ์„ผ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ทธ ๊ฐ’์„ print ํ•œ๋‹ค.

while True:
    count = 0
    sentence = input()
    if sentence == '#':
        break
    for i in sentence.lower():
        if i in vowels:
            count += 1
    print(count)

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

728x90