Problem Solving/BOJ & Programmers

[BOJ] 1032๋ฒˆ: ๋ช…๋ น ํ”„๋กฌํ”„ํŠธ

geum 2024. 10. 3. 07:50

โœ๏ธ ๋ฌธ์ œ

์‹œ์ž‘ -> ์‹คํ–‰ -> cmd๋ฅผ ์ณ๋ณด์ž. ๊ฒ€์ • ํ™”๋ฉด์ด ๋ˆˆ์— ๋ณด์ธ๋‹ค. ์—ฌ๊ธฐ์„œ dir์ด๋ผ๊ณ  ์น˜๋ฉด ๊ทธ ๋””๋ ‰ํ† ๋ฆฌ์— ์žˆ๋Š” ์„œ๋ธŒ๋””๋ ‰ํ† ๋ฆฌ์™€ ํŒŒ์ผ์ด ๋ชจ๋‘ ๋‚˜์˜จ๋‹ค. ์ด๋•Œ ์›ํ•˜๋Š” ํŒŒ์ผ์„ ์ฐพ์œผ๋ ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ•˜๋ฉด ๋œ๋‹ค.

dir *.exe๋ผ๊ณ  ์น˜๋ฉด ํ™•์žฅ์ž๊ฐ€ exe์ธ ํŒŒ์ผ์ด ๋‹ค ๋‚˜์˜จ๋‹ค. "dir ํŒจํ„ด"๊ณผ ๊ฐ™์ด ์น˜๋ฉด ๊ทธ ํŒจํ„ด์— ๋งž๋Š” ํŒŒ์ผ๋งŒ ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๋กœ ๋‚˜์˜จ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, dir a?b.exe๋ผ๊ณ  ๊ฒ€์ƒ‰ํ•˜๋ฉด ํŒŒ์ผ๋ช…์˜ ์ฒซ ๋ฒˆ์งธ ๊ธ€์ž๊ฐ€ a์ด๊ณ , ์„ธ ๋ฒˆ์งธ ๊ธ€์ž๊ฐ€ b์ด๊ณ , ํ™•์žฅ์ž๊ฐ€ exe์ธ ๊ฒƒ์ด ๋ชจ๋‘ ๋‚˜์˜จ๋‹ค. ์ด๋•Œ ๋‘ ๋ฒˆ์งธ ๋ฌธ์ž๋Š” ์•„๋ฌด๊ฑฐ๋‚˜ ๋‚˜์™€๋„ ๋œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, acb.exe, aab.exe, apb.exe๊ฐ€ ๋‚˜์˜จ๋‹ค.

์ด ๋ฌธ์ œ๋Š” ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๊ฐ€ ๋จผ์ € ์ฃผ์–ด์กŒ์„ ๋•Œ, ํŒจํ„ด์œผ๋กœ ๋ญ˜ ์ณ์•ผ ๊ทธ ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜ค๋Š”์ง€๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ๋ฌธ์ œ์ด๋‹ค. ํŒจํ„ด์—๋Š” ์•ŒํŒŒ๋ฒณ๊ณผ "." ๊ทธ๋ฆฌ๊ณ  "?"๋งŒ ๋„ฃ์„ ์ˆ˜ ์žˆ๋‹ค. ๊ฐ€๋Šฅํ•˜๋ฉด ?์„ ์ ๊ฒŒ ์จ์•ผ ํ•œ๋‹ค. ๊ทธ ๋””๋ ‰ํ† ๋ฆฌ์—๋Š” ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ์— ๋‚˜์˜จ ํŒŒ์ผ๋งŒ ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•˜๊ณ , ํŒŒ์ผ ์ด๋ฆ„์˜ ๊ธธ์ด๋Š” ๋ชจ๋‘ ๊ฐ™๋‹ค.

 

๐Ÿค– ์ž…์ถœ๋ ฅ ์˜ˆ์‹œ

 

๐Ÿ’ก ํ’€์ด

์•„์ด๋””์–ด 1) True/False ๋ฐฐ์—ด ํ™œ์šฉ

์ฒ˜์Œ์—๋Š” ํŒŒ์ผ๋ช… ๊ธธ์ด๋งŒํผ True/False ๋ฐฐ์—ด์„ ๋งŒ๋“ค๊ณ  ์ฒซ ๋ฒˆ์งธ ํŒŒ์ผ๋ช…๊ณผ ๋‚˜๋จธ์ง€ ํŒŒ์ผ๋ช…์„ ๋น„๊ตํ•˜๋ฉด์„œ ๊ฐ™์€ ์œ„์น˜&๊ฐ™์€ ๊ธ€์ž์ผ ๊ฒฝ์šฐ๋งŒ True, ์•„๋‹ˆ๋ฉด False๋กœ ๋ฐ”๊ฟ” ์ฃผ๋Š” ๋ฐฉ์‹์„ ์‚ฌ์šฉํ–ˆ๋‹ค.

 

T = int(input())

filenames = []

for _ in range(T):
    filenames.append(input())
    
standard = filenames[0]

check = [False]*len(standard)

answer = ""

for i in range(0, len(filenames)):
    for j in range(i+1, len(filenames)):
        for idx, (a, b) in enumerate(zip(filenames[i], filenames[j])):
            if a == b:
                check[idx] = True
            else:
                if check[idx]:
                    check[idx] = False
                
for idx in range(0, len(check)):
    if check[idx]:
        answer += standard[idx]
    else:
        answer += "?"

if T == 1:
    answer = filenames[0]
elif len(standard) == 1:
    answer = "?"

print(answer)

 

๋‹ค์‹œ ๋ณด๋‹ˆ๊นŒ ์ฝ”๋“œ๊ฐ€ ์ฐธ ์ง€์ €๋ถ„ํ•˜๊ตฐ!^^

 

๊ทธ๋Ÿฐ๋ฐ ์ด ๋ฐฉ์‹์œผ๋กœ ์ง„ํ–‰ํ•˜๋‹ˆ๊นŒ '์˜ˆ์ œ ์ž…๋ ฅ 1'์˜ config.sys์™€ configures์— ์žˆ๋Š” ๋งˆ์ง€๋ง‰ s์ฒ˜๋Ÿผ ๋ช‡ ๊ฐœ์˜ ํŒŒ์ผ๋ช…์—๋งŒ ์žˆ๋Š” ์•ŒํŒŒ๋ฒณ๋„ ๊ณตํ†ต ํŒจํ„ด์œผ๋กœ ์ถœ๋ ฅ๋ผ์„œ ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์„ ์ƒ๊ฐํ•ด๋ณด๊ธฐ๋กœ ํ–ˆ๋‹ค.

 

์•„์ด๋””์–ด 2) ๋ฌธ์ž ๋“ฑ์žฅ ๋นˆ๋„ ํ™•์ธ ๋ฐฐ์—ด ํ™œ์šฉ

์ฒซ ๋ฒˆ์งธ ์ฝ”๋“œ๋กœ 'ํ‹€๋ ธ์Šต๋‹ˆ๋‹ค'๋ฅผ ๋ฐ›๊ณ  ๋‚˜์„œ ๋ฌธ์ œ๋ฅผ ๋‹ค์‹œ ์ฝ์–ด ๋ณด๋‹ค๊ฐ€, ?๊ฐ€ ์•„๋‹Œ ์•ŒํŒŒ๋ฒณ์œผ๋กœ ์ถœ๋ ฅ๋˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๊ฐ ์ž๋ฆฌ์˜ ์•ŒํŒŒ๋ฒณ์ด ์ •ํ™•ํžˆ N๋ฒˆ ๋‚˜์™€์•ผ ํ•œ๋‹ค๋Š” ์‚ฌ์‹ค์„ ๋ฐœ๊ฒฌํ–ˆ๋‹ค.

 

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

 

T = int(input())

filenames = []

answer = ""

for _ in range(T):
    filenames.append(input())
    
standard = filenames[0]

check = [0]*len(standard)

for i in range(1, len(filenames)):
    for j in range(0, len(standard)):
        if filenames[i][j] == standard[j]:
            check[j] += 1

for k in range(0, len(standard)):
    if check[k] == T-1:
        answer += standard[k]
    else:
        answer += "?"

print(answer)