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

77-tgyuuAn #247

Merged
merged 1 commit into from
Oct 10, 2024
Merged

77-tgyuuAn #247

merged 1 commit into from
Oct 10, 2024

Conversation

tgyuuAn
Copy link
Member

@tgyuuAn tgyuuAn commented Sep 27, 2024

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

ํ‘œ ๋ณ‘ํ•ฉ

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

ํ‘๋ฐฑ ์š”๋ฆฌ์‚ฌ ๋ณด๋ฉด์„œ ํ’€์–ด์„œ 3์‹œ๊ฐ„ ใ…‹ใ…‹

(์•„์˜ค ์ค‘๊ฐ„์— ๋””๋ฒ„๊น… ์ง€์˜ฅ, ๋‚˜ํƒœ์ง€์˜ฅ๋„ ์žˆ์—ˆ์Œ)

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

image

์ง„์งœ ๊ตฌํ˜„ ๋ฌธ์ œ์ธ๋ฐ...

์ด์ œ MERGE, UNMERGE ๊ฐ€ ๋ณต๋ณ‘์ธ ๋ฌธ์ œ.

๊ทผ๋ฐ ๊ทธ๊ฒŒ ๋ง‰ ๊ทธ๋ ‡๊ฒŒ ์–ด๋ ค์šด ๊ฑด ์•„๋‹ˆ๊ณ  ์ฒ˜๋ฆฌ๊ฐ€ ๊ท€์ฐฎ์Œ.




์•„ ์ง„์งœ ์ฃ„์†กํ•œ๋ฐ, ์ด๊ฑฐ ๊ตํ™ฉ์ด๋„ ํ’€์–ด์„œ

๊ตฌํ˜„ ๋ฌธ์ œ์ด๊ธฐ๋„ ํ•˜๊ณ ...

์ง„์งœ ๋ฌธ์ œ์—์„œ ์‹œํ‚ค๋Š”๋Œ€๋กœ ํ’€๋ฉด๋˜๊ฑฐ๋“ ์š”....

AlgoLeadMe/AlgoLeadMe-3#83

์ง„์งœ ๋‚ ๋จน์ข€ํ• ๊ฒŒ์š” ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ ;;

image

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

์ ˆ๋•Œ ๋””๋ฒ„๊น…์„ ๋ฏธ๋ฃจ์ง€๋งˆ.

์ ˆ๋•Œ ๋””๋ฒ„๊น…์„ ๋ฌด์„œ์›Œํ•˜์ง€๋งˆ

KakaoTalk_Snapshot_20240927_181117

@tgyuuAn tgyuuAn added tgyuuAn ํ•œ ์ค„๋กœ๋Š” ์†Œ๊ฐœํ•  ์ˆ˜ ์—†๋Š” ๋‚จ์ž. ์ž‘์„ฑ ์ค‘ โฑ๏ธ labels Sep 27, 2024
@tgyuuAn tgyuuAn self-assigned this Sep 27, 2024
@tgyuuAn tgyuuAn marked this pull request as ready for review September 27, 2024 09:12
@H0ngJu H0ngJu self-requested a review October 4, 2024 06:21
Copy link
Collaborator

@H0ngJu H0ngJu left a comment

Choose a reason for hiding this comment

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

๊ตฌํ˜„ ๋ฌธ์ œ๋Š” ํ•ญ์ƒ ์žฌ๋ฐŒ๋„ค์˜ˆ ^~^ MERGE ๋•Œ๋ฌธ์— ๋‘์„ธ๋ฒˆ ๋น ๊พธ๋จน๊ณ  ํ’€์—ˆ์Šต๋‹ˆ๋‹น

commands = ["UPDATE 1 1 a", "UPDATE 1 2 b", "UPDATE 2 1 c", "UPDATE 2 2 d", "MERGE 1 1 1 2", "MERGE 2 2 2 1", "MERGE 2 1 1 1", "PRINT 1 1", "UNMERGE 2 2", "PRINT 1 1"]
table = {(i, j): "EMPTY" for i in range(1,51) for j in range(1,51)}
mergeble = {(i, j): [] for i in range(1,51) for j in range(1,51)}
print_arr = []

for cmds in commands:
    tokens = cmds.split()
    tokens_len = len(tokens)

    if tokens[0] == "UPDATE" and tokens_len == 4:
        r = int(tokens[1])
        c = int(tokens[2])
        value = tokens[3]

        if mergeble[(r,c)] != []:
            for (mr, mc) in mergeble[(r,c)]:
                table[(mr,mc)] = value
        else:
            table[(r,c)] = value

    elif tokens[0] == "UPDATE" and tokens_len == 3:
        value1 = tokens[1]
        value2 = tokens[2]

        for key, value in table.items():
            if value == value1:
                table[key] = value2

    elif tokens[0] == "MERGE":
        r1 = int(tokens[1])
        c1 = int(tokens[2])
        r2 = int(tokens[3])
        c2 = int(tokens[4])
        tmp = "EMPTY"

        if r1 == r2 and c1 == c2:
            continue
        
        if not ((r1 == r2 and abs(c1 - c2) == 1) or (c1 == c2 and abs(r1 - r2) == 1)):
            continue

        if table[(r1,c1)] != "EMPTY" and table[(r2,c2)] != "EMPTY":
            tmp = table[(r1,c1)]
        elif table[(r1,c1)] != "EMPTY":
            tmp = table[(r1,c1)]
        elif table[(r2,c2)] != "EMPTY":
            tmp = table[(r2,c2)]

        merged_list = set(mergeble[(r1, c1)] + mergeble[(r2, c2)] + [(r1, c1), (r2, c2)])
        for (mr, mc) in merged_list:
            mergeble[(mr, mc)] = list(merged_list)

        table[(r2, c2)] = tmp
        for (mr, mc) in mergeble[(r1, c1)]:
            table[(mr, mc)] = tmp

    elif tokens[0] == "UNMERGE":
        r = int(tokens[1])
        c = int(tokens[2])

        merged_cells = mergeble[(r, c)][:]
        mergeble[(r, c)] = []

        original_value = table[(r, c)]
        for (mr, mc) in merged_cells:
            table[(mr, mc)] = "EMPTY"
            mergeble[(mr, mc)] = []

        table[(r, c)] = original_value

    elif tokens[0] == "PRINT":
        r = int(tokens[1])
        c = int(tokens[2])

        print_arr.append(table[(r,c)])
    else:
        continue

print(print_arr)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tgyuuAn ํ•œ ์ค„๋กœ๋Š” ์†Œ๊ฐœํ•  ์ˆ˜ ์—†๋Š” ๋‚จ์ž. ๋ฆฌ๋ทฐ ์™„๋ฃŒ โœ”๏ธ
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants