Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

12-seongwon030 #50

Merged
merged 1 commit into from
May 23, 2024
Merged

12-seongwon030 #50

merged 1 commit into from
May 23, 2024

Conversation

seongwon030
Copy link
Collaborator

๐Ÿ”— ๋ฌธ์ œ ๋งํฌ

์•”ํ˜ธ ๋งŒ๋“ค๊ธฐ

โœ”๏ธ ์†Œ์š”๋œ ์‹œ๊ฐ„

2์‹œ๊ฐ„

โœจ ์ˆ˜๋„ ์ฝ”๋“œ

๋ธŒ๋ฃจํŠธํฌ์Šค๋ผ๊ณ  ํ•˜๋‹ˆ ๋ชจ๋“  ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ์ฐพ๋Š” ๊ฒŒ ์šฐ์„ ์ด๋ผ๊ณ  ์ƒ๊ฐํ–ˆ๋‹ค. ์ฒ˜์Œ์—” ๋ชจ์Œ๋ฆฌ์ŠคํŠธ์™€ ์ž์Œ๋ฆฌ์ŠคํŠธ๋กœ ๋‚˜๋ˆ„์–ด ๋ชจ์Œ๋ฆฌ์ŠคํŠธ ์กฐํ•ฉ๊ณผ ์ž์Œ๋ฆฌ์ŠคํŠธ ์กฐํ•ฉ์„ ๋”ฐ๋กœ ๋งŒ๋“ค์–ด ๋‘ ๊ฐœ๋ฅผ ํ•ฉ์น˜๋Š” ๋ฐฉ์‹์œผ๋กœ ํ–ˆ๋”๋‹ˆ ์ถœ๋ ฅ์ดˆ๊ณผ๊ฐ€ ๋‚ฌ๋‹ค. ๋‹ค๋ฅธ ํ…Œ์ŠคํŠธ์ผ€์ด์Šค๋ฅผ ๋‹ค ๋„ฃ์–ด๋ดค๋Š”๋ฐ๋„ ํ†ต๊ณผ๋˜์ง€ ์•Š์•˜๋‹ค..

ํžŒํŠธ

์งˆ๋ฌธ๊ฒŒ์‹œํŒ์—์„œ ํ…Œ์ŠคํŠธ์ผ€์ด์Šค๋ฅผ ์ฐพ์•„ ๋ณด๋‹ค๊ฐ€ ์–ด๋–ค ์‚ฌ๋žŒ์˜ ๋‹ต๋ณ€์ด ํžŒํŠธ๊ฐ€ ๋˜์—ˆ๋‹ค. L,C๊ฐ€ 15์ดํ•˜๋ฉด ๋ชจ๋“  ์กฐํ•ฉ์˜ ๊ฐœ์ˆ˜๊ฐ€ C์ค‘ L๊ฐœ๋ฅผ ๋ฝ‘๋Š” ๊ฒฝ์šฐ์˜ ์ˆ˜์ธ๋ฐ ๊ทธ๋ ‡๊ฒŒ ๋งŽ์€ ๊ฒฝ์šฐ์˜ ์ˆ˜๊ฐ€ ํ•„์š”ํ•˜์ง€ ์•Š๊ฒ ๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“ค์—ˆ๋‹ค. ๊ทธ๋ž˜์„œ ๋ชจ๋“  ๊ฒฝ์šฐ์˜ ์กฐํ•ฉ์„ ์ˆœํšŒํ•˜๋ฉด์„œ ๊ทธ ์กฐํ•ฉ์— ๋ชจ์Œ์ด ์ตœ์†Œ 1๊ฐœ ๊ทธ๋ฆฌ๊ณ  ์ž์Œ์ด ์ตœ์†Œ 2๊ฐœ ์žˆ๋Š”์ง€ ์ฒดํฌํ•˜๋ฉด์„œ ์กฐ๊ฑด์— ๋งŒ์กฑํ•˜๋ฉด result ๋ฐฐ์—ด์— ๋„ฃ์€ ๋‹ค์Œ ๋งˆ์ง€๋ง‰์— sort()๋ฅผ ์จ์„œ ์ถœ๋ ฅํ–ˆ๋‹ค.

์ฃผ์˜ํ•  ๊ฒƒ

  vowel_str = ''.join(sorted(c))

์กฐํ•ฉ ๋ฌธ์ž์—ด์„ ์ฒดํฌํ•  ๋•Œ sorted()๋กœ ๋ฌธ์ž์—ด์„ ์ •๋ ฌํ•ด์ค˜์•ผ ๋‚˜์ค‘์— ์‚ฌ์ „์‹์œผ๋กœ ์ถœ๋ ฅ์ด ๋œ๋‹ค.

๐Ÿ“š ์ƒˆ๋กญ๊ฒŒ ์•Œ๊ฒŒ๋œ ๋‚ด์šฉ

๋ธŒ๋ฃจํŠธํฌ์Šค๋Š” ๋ฌด์‹ํ•˜๊ฒŒ ํ•˜๋Š”๊ฒŒ ๋งž๋Š” ๊ฒƒ ๊ฐ™๋‹ค. ์ผ๋‹จ ๋ชจ๋“  ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ์ƒ๊ฐํ•ด๋ณด๊ณ  ์•ˆ ๋˜๋ฉด ๋‹ค์Œ ๋ฐฉ๋ฒ•์œผ๋กœ ๊ฐ€๋Š” ๋ฐฉํ–ฅ์œผ๋กœ..

Copy link
Collaborator

@InSange InSange left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์˜ค๋ฆ„์ฐจ์ˆœ์ด๊ณ  ํฌ๊ธฐ๊ฐ€ 15์ผ๋•Œ ์•„๋ฌด๋ฆฌ ์ปค๋„ 8์ž๋ฆฌ * (26 ์•ŒํŒŒ๋ฒณ์—์„œ ์ ˆ๋ฐ˜์˜ ๊ฐ€๋Šฅ์„ฑ b-> (j < alpha)) ์ˆœ์œผ๋กœ ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿผ ์˜ฌ ์ˆ˜ ์žˆ๋Š” ๊ฐ€๋Šฅ์„ฑ์€ 8!์ •๋„? ๋  ์ˆ˜ ์žˆ๊ฒ ๋„ค์š”..
๊ทธ๋Ÿผ ์•„๋งˆ ๋‚˜์˜ฌ์ˆ˜ ์žˆ๋Š” ์˜ค๋ฆ„์ฐจ์ˆœ ๋‹จ์–ด์˜ ์กฐํ•ฉ์€ 322,560์ •๋„๊ฐ€ ๋‚˜์˜ฌ ๊ฒƒ์œผ๋กœ ์˜ˆ์ƒํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ๋ด…๋‹ˆ๋‹ค.

์ €๋Š” ๋จผ์ € sort๋ฅผ ํ•ด์„œ ๋งจ ์•ž ์š”์†Œ๋ถ€ํ„ฐ L ํฌ๊ธฐ๊นŒ์ง€ ๋น„๊ต๋ฅผ ์ง„ํ–‰ํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
๋ชจ์Œ ์š”์†Œ๋ฅผ ๋น„๊ตํ•ด์ค„ ํ•จ์ˆ˜๋ฅผ ํ•˜๋‚˜ ๊ตฌํ˜„ํ•˜์—ฌ ์ฒซ๋ฒˆ์งธ ๋‹จ์–ด ๋ถ€ํ„ฐ L ํฌ๊ธฐ๊นŒ์ง€ ๋‹จ์–ด๋ฅผ ์ถ”๊ฐ€ํ•œ string์—์„œ ๋งŒ์•ฝ ํ•จ์ˆ˜์—์„œ ๋ชจ์Œ์ด ํฌํ•จ๋˜์–ด ์žˆ๋‹ค๊ณ  ํŒ๋ณ„๋  ์‹œ boolํ˜• flag ๋ณ€์ˆ˜๋ฅผ ํ†ตํ•ด ํ•ด๋‹น ๋‹จ์–ด๋Š” ์กฐ๊ฑด์— ๋งŒ์กฑํ•œ๋‹ค๊ณ  ํ‘œ์‹œํ•˜์—ฌ ๋ฒกํ„ฐ์— ๋„ฃ๋Š” ์‹์œผ๋กœ ์ง„ํ–‰ํ•œ๋‹ค๋ฉด ์–ด๋–จ๊นŒ์š”?

@seongwon030
Copy link
Collaborator Author

์˜ค๋ฆ„์ฐจ์ˆœ์ด๊ณ  ํฌ๊ธฐ๊ฐ€ 15์ผ๋•Œ ์•„๋ฌด๋ฆฌ ์ปค๋„ 8์ž๋ฆฌ * (26 ์•ŒํŒŒ๋ฒณ์—์„œ ์ ˆ๋ฐ˜์˜ ๊ฐ€๋Šฅ์„ฑ b-> (j < alpha)) ์ˆœ์œผ๋กœ ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿผ ์˜ฌ ์ˆ˜ ์žˆ๋Š” ๊ฐ€๋Šฅ์„ฑ์€ 8!์ •๋„? ๋  ์ˆ˜ ์žˆ๊ฒ ๋„ค์š”.. ๊ทธ๋Ÿผ ์•„๋งˆ ๋‚˜์˜ฌ์ˆ˜ ์žˆ๋Š” ์˜ค๋ฆ„์ฐจ์ˆœ ๋‹จ์–ด์˜ ์กฐํ•ฉ์€ 322,560์ •๋„๊ฐ€ ๋‚˜์˜ฌ ๊ฒƒ์œผ๋กœ ์˜ˆ์ƒํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ๋ด…๋‹ˆ๋‹ค.

์ €๋Š” ๋จผ์ € sort๋ฅผ ํ•ด์„œ ๋งจ ์•ž ์š”์†Œ๋ถ€ํ„ฐ L ํฌ๊ธฐ๊นŒ์ง€ ๋น„๊ต๋ฅผ ์ง„ํ–‰ํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๋ชจ์Œ ์š”์†Œ๋ฅผ ๋น„๊ตํ•ด์ค„ ํ•จ์ˆ˜๋ฅผ ํ•˜๋‚˜ ๊ตฌํ˜„ํ•˜์—ฌ ์ฒซ๋ฒˆ์งธ ๋‹จ์–ด ๋ถ€ํ„ฐ L ํฌ๊ธฐ๊นŒ์ง€ ๋‹จ์–ด๋ฅผ ์ถ”๊ฐ€ํ•œ string์—์„œ ๋งŒ์•ฝ ํ•จ์ˆ˜์—์„œ ๋ชจ์Œ์ด ํฌํ•จ๋˜์–ด ์žˆ๋‹ค๊ณ  ํŒ๋ณ„๋  ์‹œ boolํ˜• flag ๋ณ€์ˆ˜๋ฅผ ํ†ตํ•ด ํ•ด๋‹น ๋‹จ์–ด๋Š” ์กฐ๊ฑด์— ๋งŒ์กฑํ•œ๋‹ค๊ณ  ํ‘œ์‹œํ•˜์—ฌ ๋ฒกํ„ฐ์— ๋„ฃ๋Š” ์‹์œผ๋กœ ์ง„ํ–‰ํ•œ๋‹ค๋ฉด ์–ด๋–จ๊นŒ์š”?

from itertools import combinations

L,C = map(int,input().split())

k = list(map(str,input().split()))
k.sort()

vowels = 'aeiou'

com = combinations(k,L)

for c in com:
  vowel_cnt = sum(1 for char in c if char in vowels)
  consonant_cnt = L - vowel_cnt
  if vowel_cnt>=1 and consonant_cnt>=2:
    print(''.join(c))

๊ทธ๋ ‡๊ฒŒ ์งœ๋ดค๋Š”๋ฐ์š”. ๋ชจ์Œ์˜ ๊ฐœ์ˆ˜๊ฐ€ 1๊ฐœ ์ด์ƒ์ธ์ง€๋งŒ ํŒ๋ณ„ํ•˜๊ฒŒ ๋˜๋ฉด L=3์ผ ๋•Œ ๋ชจ์Œ์˜ ๊ฐœ์ˆ˜๊ฐ€ 2๊ฐœ๋ฉด ์ž์Œ์˜ 1๊ฐœ ์กด์žฌํ•˜๋Š” ์˜ˆ์™ธ์ƒํ™ฉ์ฒ˜๋Ÿผ ์ž์Œ์ด ์ตœ์†Œ 2๊ฐœ ์กด์žฌํ•œ๋‹ค๋Š” ์กฐ๊ฑด์„ ๊ฐ„๊ณผํ•˜๊ฒŒ ๋˜๋Š” ๊ฒƒ ๊ฐ™์•„์š”. ๊ทธ๋ž˜๋„ ๋จผ์ € sort()ํ•˜๊ณ  ์ฝ”๋“œ๋ฅผ ์งœ๋‹ˆ๊นŒ ๋” ๊น”๋”ํ•ด์ง„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

vowel_str = ''.join(sorted(c))
vowel_cnt = sum(1 for char in vowel_str if char in vowels)
consonant_cnt = L - vowel_cnt
if vowel_cnt >=1 and consonant_cnt >=2:
Copy link
Collaborator

@yuyu0830 yuyu0830 May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ฐ„๋‹จํ•œ ํŒ์ธ๋ฐ x == 1 ์ด๋‚˜ x >= 1 ๊ฐ™์€ ์ฝ”๋“œ๋Š” ๊ทธ๋ƒฅ x๋กœ ์“ฐ๋ฉด ๊ฐ™์€ ํšจ๊ณผ๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!

Copy link
Collaborator

@yuyu0830 yuyu0830 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ฏธ๋ฆฌ ์ •๋ ฌํ•˜๊ณ  ํƒ์ƒ‰ํ–ˆ๋‹ค๋ฉด ์กฐ๊ธˆ ๋” ์‹œ๊ฐ„์„ ์ค„์ผ ์ˆ˜ ์žˆ์—ˆ์„ ๊ฒƒ ๊ฐ™๋„ค์š”..! ํŠนํžˆ ๋ฏธ๋ฆฌ ์ •๋ ฌ์„ ํ•ด๋’€๋‹ค๋ฉด ์ •๋ ฌ ์ˆœ์„œ๊ฐ€ ๋ณด์žฅ๋˜๊ธฐ ๋•Œ๋ฌธ์— append๋กœ ๊ฒฐ๊ณผ๋ฅผ ๋ชจ์„ ํ•„์š” ์—†์ด ๊ทธ๋•Œ๊ทธ๋•Œ ์ถœ๋ ฅํ•ด๋„ ๋œ๋‹ค๋Š” ์žฅ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค!

ํŒŒ์ด์ฌ ์Šคํƒ€์ผ๋กœ ๋ชจ์Œ ๊ฐœ์ˆ˜ ์„ธ๋Š” ํŒŒํŠธ๊ฐ€ ์‹ ๊ธฐํ•˜๋„ค์š” ใ…‹ใ…‹

Copy link
Contributor

@dhlee777 dhlee777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ฒ˜์Œ๋ถ€ํ„ฐ ๋ชจ์Œ๋ฆฌ์ŠคํŠธ์™€ ์ž์Œ๋ฆฌ์ŠคํŠธ๋ฅผ ๋‚˜๋ˆ„๋Š”๊ฒƒ ๋ณด๋‹ค ๋ชจ๋“ ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ํƒ์ƒ‰ํ•ด์ฃผ๋ฉฐ ์กฐํ•ฉ์—์„œ ๋ชจ์Œ์ด ์ตœ์†Œ 1๊ฐœ ๊ทธ๋ฆฌ๊ณ  ์ž์Œ์ด ์ตœ์†Œ 2๊ฐœ์ธ๊ฒฝ์šฐ์—๋งŒ result ์— ๋„ฃ์–ด์ฃผ๋Š” ๋ธŒ๋ฃจํŠธํฌ์Šค ๋ฐฉ์‹์ด๋„ค์š” ์ด๋ ‡๊ฒŒ ๊ฒฝ์šฐ์˜์ˆ˜๊ฐ€ ๋งŽ์ง€์•Š์€๊ฒฝ์šฐ ๋ธŒ๋ฃจํŠธํฌ์Šค๊ฐ™์€ ๋…ธ๊ฐ€๋‹ค๋„ ํšจ์œจ์ ์ธ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants