We will find a way, we always have.

-interstellar

Problem Solving/๋ฐฑ์ค€

[๋ฐฑ์ค€] 25192๋ฒˆ: ์ธ์‚ฌ์„ฑ ๋ฐ์€ ๊ณฐ๊ณฐ์ด - ํŒŒ์ด์ฌ

Redddy 2022. 5. 22. 20:46

๐Ÿงฉ๋ฌธ์ œ ํ•ด์„

์ฑ„ํŒ…๋ฐฉ์—์„œ ์‚ฌ์šฉํ•œ ์ž„ํ‹ฐ๊ฐฏ์ˆ˜๋ฅผ ์ถœ๋ ฅํ•˜๋ฉด ๋˜๋Š” ๋ฌธ์ œ์˜€๋‹ค. ์‚ฌ๋žŒ๋“ค์€ ์ƒˆ๋กœ์šด ์‚ฌ๋žŒ์ด ๋“ค์–ด์™”์„ ๋•Œ ์ž„ํ‹ฐ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ๊ทธ ๋‹ค์Œ์€ ์ผ๋ฐ˜ ๋Œ€ํ™”๋ฅผ ์ด์–ด๋‚˜๊ฐ„๋‹ค. ์ฆ‰, ์ƒˆ๋กœ์šด ๋“ค์–ด์™”์„ ๋•Œ ์‚ฌ์šฉํ•œ ์ž„ํ‹ฐ ๊ฐฏ์ˆ˜๋ฅผ ์ „๋ถ€ ๋”ํ•ด์ฃผ๋ฉด ๋˜๋Š” ๋ฌธ์ œ์ด๋‹ค.

 

๐Ÿ“• ํ’€์ด

dict() ์ž๋ฃŒํ˜•์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ํ’€์—ˆ๋‹ค. ์ƒˆ๋กœ์šด ์‚ฌ๋žŒ์ด ๋“ค์–ด์˜ค๋ฉด dict()์˜ ๊ฐ’๋“ค์„ ๋ฆฌ์…‹ํ•ด์ฃผ์—ˆ๋‹ค.

 

๐Ÿ’ป ์ฝ”๋“œ

import sys
input = sys.stdin.readline
cnt = 0 # ์ž„ํ‹ฐ๊ฐฏ์ˆ˜ ๋ณ€์ˆ˜
user = {} # ์ด๋ฆ„๊ณผ ์ž„ํ‹ฐ์‚ฌ์šฉ์„ ํ™•์ธํ•  ๋ณ€์ˆ˜

for i in range(int(input().rstrip())): # ์ฑ„ํŒ…๋ฐฉ์˜ ๊ธฐ๋ก์ˆ˜๋งŒํผ for๋ฌธ์„ ๋Œ๋ฆฐ๋‹ค
    # ์ฑ„ํŒ…๋‚ด์šฉ์ž…๋ ฅ๋ฐ›์Œ
    s = input().rstrip()
    # ์ƒˆ๋กœ์šด ์‚ฌ๋žŒ์ด ๋“ค์–ด์™”์„๋•Œ
    if s == "ENTER":
    	# ์ด์ „๊นŒ์ง€ ์žˆ์—ˆ๋˜ ์ž„ํ‹ฐ์ˆ˜๋ฅผ ์ „๋ถ€ ๋”ํ•œ๋‹ค
        cnt += sum(user.values())
        # dict() ์ดˆ๊ธฐํ™”
        user = {}
    else:
    	# ์ „์— ์—†์—ˆ๋˜ ์ด๋ฆ„์ด๋ผ๋ฉด ์ถ”๊ฐ€
        if s not in user: 
        	user[s] = 1
        # ์ „์— ์žˆ์—ˆ๋˜ ์ด๋ฆ„์ด๋ผ๋ฉด ํŒจ์Šค

# user์— ๋‚จ์•„์žˆ๋Š” ๊ฐ’๋“ค๋„ ๋”ํ•ด์ค€๋‹ค.
cnt += sum(user.values())

print(cnt)

 

๐Ÿ”— ๋ฌธ์ œ๋งํฌ : ์ธ์‚ฌ์„ฑ ๋ฐ์€ ๊ณฐ๊ณฐ์ด

 

25192๋ฒˆ: ์ธ์‚ฌ์„ฑ ๋ฐ์€ ๊ณฐ๊ณฐ์ด

์ฒซ๋ฒˆ์งธ ์ƒˆ๋กœ์šด ์‚ฌ๋žŒ์ด ๋“ค์–ด์˜จ ๋’ค  pjshwa, chansol, chogahui05์€ ๋ชจ๋‘ ๊ณฐ๊ณฐํ‹ฐ์ฝ˜์œผ๋กœ ์ธ์‚ฌํ–ˆ๋‹ค. ๋‘๋ฒˆ์งธ ์ƒˆ๋กœ์šด ์‚ฌ๋žŒ์ด ๋“ค์–ด์˜จ ๋’ค  pjshwa์™€ chansol์€ ๋‹ค์‹œ ๊ณฐ๊ณฐํ‹ฐ์ฝ˜์œผ๋กœ ์ธ์‚ฌํ–ˆ๋‹ค.

www.acmicpc.net

๊ณฐ๊ณฐ์ด