Algorithm Problem/Python

[python] SWEA - 7675. ํ†ต์—ญ์‚ฌ ์„ฑ๊ฒฝ์ด

deo2kim 2020. 12. 7. 17:52
๋ฐ˜์‘ํ˜•

๐Ÿค”๋ฌธ์ œ ํ•ด๊ฒฐ

  • D3 | ๋ฌธ์ž์—ด

๐Ÿ’จ ๋ฌธ์žฅ์œผ๋กœ ๊ตฌ๋ถ„ํ•˜๊ณ , ๋‹จ์–ด๋กœ ๊ตฌ๋ถ„ํ•˜๊ธฐ

๐Ÿ’จ ์ด๋ฆ„์ด ๋˜๋Š” ์กฐ๊ฑด์€

์ฒซ๋ฒˆ์งธ ๊ธ€์ž๊ฐ€ ๋Œ€๋ฌธ์ž์ด๊ณ , ๋‚˜๋จธ์ง€๋Š” ์†Œ๋ฌธ์ž์ด๋‹ค.

์ฒซ๋ฒˆ์งธ ๊ธ€์ž๊ฐ€ ํ•˜๋‚˜์ผ ๊ฒฝ์šฐ๋Š” ์ด๋ฆ„์ด๋‹ค.

( ์ˆซ์ž๊ฐ€ ์„ž์ด๋ฉด x, ์ฒซ๋ฒˆ์งธ๋Š” ๋ฌด์กฐ๊ฑด ์†Œ๋ฌธ์ž, ๋’ค์— ์ ์ด๋“  ๋Š๋‚Œํ‘œ๋“  ๋ฌผ์Œํ‘œ๋“  ํ•„์š”์—†๋‹ค )

 

์œ„์˜ ๋‘๊ฐ€์ง€ ๊ฒฝ์šฐ๊ฐ€ ๋์ด๋‹ค. ๋ฌธ์ œ๋ฅผ ์กฐ๊ธˆ ํ—ท๊ฐˆ๋ฆฌ๊ฒŒ....

 

๐Ÿ’ป์†Œ์Šค ์ฝ”๋“œ

for tc in range(int(input())):
    N = int(input())
    answer = list()
    sentence = input()

    # ๋ฌธ์žฅ ๊ตฌ๋ถ„ํ•˜๊ธฐ
    start = 0
    for i in range(len(sentence)):
        if sentence[i] in ('!', '?', '.'):
            # ๋‹จ์–ด๋กœ ๊ตฌ๋ถ„ํ•˜๊ธฐ
            cnt = 0
            for word in sentence[start:i].split():
                # ์ด๋ฆ„์ธ์ง€ ํŒ๋ณ„ํ•˜๊ธฐ
                if (len(word) == 1 and word[0].isupper()) or (
                        word[0].isupper() and word.isalpha() and word[1:].islower()):
                    cnt += 1
            start = i + 2

            answer.append(cnt)

    print(f'#{tc + 1}', *answer)

๐Ÿ“•๋ฌธ์ œ ํ™•์ธ

์ถœ์ฒ˜: SW Expert Academy

 

SW Expert Academy

SW ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์—ญ๋Ÿ‰ ๊ฐ•ํ™”์— ๋„์›€์ด ๋˜๋Š” ๋‹ค์–‘ํ•œ ํ•™์Šต ์ปจํ…์ธ ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!

swexpertacademy.com

 

๋ฐ˜์‘ํ˜•