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

9-oesnuj #30

Merged
merged 5 commits into from
Jul 10, 2024
Merged

9-oesnuj #30

merged 5 commits into from
Jul 10, 2024

Conversation

oesnuj
Copy link
Member

@oesnuj oesnuj commented May 30, 2024

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

๋ฐฑ์ค€ | ๋น™๊ณ 

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

40๋ถ„

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

[๋ฌธ์ œ ์กฐ๊ฑด]
๋น™๊ณ ํŒ์— ์“ฐ์—ฌ์ง„ ์ˆ˜์™€ ์‚ฌํšŒ์ž๊ฐ€ ๋ถ€๋ฅด๋Š” ์ˆ˜๋Š” ๊ฐ๊ฐ 1๋ถ€ํ„ฐ 25๊นŒ์ง€์˜ ์ˆ˜๊ฐ€ ํ•œ ๋ฒˆ์”ฉ ์‚ฌ์šฉ๋œ๋‹ค.

Note

  1. 5x5 ๋ฐฐ์—ด๋กœ ๋น™๊ณ  ๋ณด๋“œ๋ฅผ ์ดˆ๊ธฐํ™”

  2. 1๋ถ€ํ„ฐ 25๊นŒ์ง€์˜ ์ˆซ์ž๋ฅผ ์ˆœ์„œ๋Œ€๋กœ ๋ถ€๋ฆ„

  3. ์ˆซ์ž๋ฅผ ๋ถ€๋ฅผ ๋•Œ๋งˆ๋‹ค ํ•ด๋‹น ์ˆซ์ž๊ฐ€ ๋น™๊ณ  ๋ณด๋“œ์— ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๊ณ , ์žˆ์œผ๋ฉด ํ•ด๋‹น ์นธ์„ 0์œผ๋กœ ๋ณ€๊ฒฝํ•˜๊ณ  ๋น™๊ณ ์˜ ๊ฐฏ์ˆ˜๋ฅผ ์ฒดํฌ

  4. ๋น™๊ณ ์˜ ๊ฐฏ์ˆ˜๊ฐ€ 3์ค„ ์ด์ƒ์ด ๋˜๋ฉด ๊ทธ ๋•Œ์˜ ์ˆซ์ž ์ˆœ์„œ๋ฅผ ์ถœ๋ ฅ

ํ•ด๋‹น ์นธ์„ 0์œผ๋กœ ๋ณ€๊ฒฝํ•˜๋Š” ํ•จ์ˆ˜ changeBingo
ํ˜„์žฌ ๋ณด๋“œํŒ์˜ ๋น™๊ณ  ๊ฐฏ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜ checkBingo
-> ์ด์ค‘ ๋ฐ˜๋ณต๋ฌธ์„ ํ™œ์šฉํ•ด 0์ด ์—ฐ์† 5๊ฐœ๊ฐ€ ๋‚˜์˜จ๋‹ค๋ฉด ๋น™๊ณ  ๊ฐฏ์ˆ˜๋ฅผ 1 ์ฆ๊ฐ€์‹œํ‚ค๋Š” ๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„

โš  ์ฃผ์˜ํ–ˆ๋˜ ์ 

๋น™๊ณ ์ค„์ด 3๊ฐœ๊ฐ€ ๋˜๋ฉด ์ข…๋ฃŒ๊ฐ€ ๋˜๋Š”๊ฑด๋ฐ ๋งŒ์•ฝ 2๊ฐœ์˜ ๋น™๊ณ ์ค„์—์„œ ๋‹ค์Œ ์ˆซ์ž ๋ถ€๋ฆ„์—์„œ ๋น™๊ณ ์ค„์ด 4๊ฐœ๊ฐ€ ๋˜์–ด๋ฒ„๋ฆฌ๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๊ธฐ์— 3๊ฐœ ์ด์ƒ์ด ๋ ๋•Œ๋กœ ์ ์—ˆ์–ด์•ผํ–ˆ์Šต๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ ์ข€ ํ—ค๋งธ๋„ค์š”

if (checkBingo() == 3) //ํ‹€๋ฆผ
if (checkBingo() >= 3) //๋งž์Œ

๐Ÿ“‚ ์ „์ฒด ์ฝ”๋“œ

#include <iostream>
using namespace std;

const int BINGO_SIZE = 5;
int board[BINGO_SIZE][BINGO_SIZE];

void changeBingo(int target);
int checkBingo();



int main()
{
    ios::sync_with_stdio(0);    cin.tie(0);
	for (int i = 0; i < BINGO_SIZE; i++)
	{
		for (int j = 0; j < BINGO_SIZE; j++)
		{
			cin >> board[i][j];
		}
	}

	int sayCnt = 0;
	for (int i = 0; i < BINGO_SIZE * BINGO_SIZE; i++) //์‚ฌํšŒ์ž๊ฐ€ ๋งํ•˜๋Š” ์ˆซ์ž๋งˆ๋‹ค ๋น™๊ณ ํŒ ์ฒ˜๋ฆฌ
	{
			int num;
			cin >> num;
			sayCnt++;
			changeBingo(num);
			if (checkBingo() >= 3) {
				cout << sayCnt;
				return 0;
			}
	}
	return 0;
}


void changeBingo(int target)  //์‚ฌํšŒ์ž๊ฐ€ ๋ถ€๋ฅธ ์ˆ˜ ์ฒดํฌํ•˜๊ธฐ
{
	for (int i = 0; i < BINGO_SIZE; i++){
		for (int j = 0; j < BINGO_SIZE; j++){
			if (board[i][j] == target){
				board[i][j] = 0;
				return;
			}
		}
	}
	return;
}

int checkBingo() //ํ˜„์žฌ ๋ณด๋“œํŒ์— ๋น™๊ณ ๊ฐ€ ๋ช‡์ค„์ธ์ง€
{
	int bingoCnt = 0;

	for (int i = 0; i < BINGO_SIZE; i++)  //๊ฐ€๋กœ, ์„ธ๋กœ ๋น™๊ณ  ํ™•์ธ
	{
		int horizontal = 0, vertical = 0;
		for (int j = 0; j < BINGO_SIZE; j++){
			if (!board[i][j])
				horizontal++;
			if (!board[j][i])
				vertical++;
		}
		if (horizontal == BINGO_SIZE) bingoCnt++;
		if (vertical == BINGO_SIZE) bingoCnt++;
	}													

	int right_diagonal = 0, left_diagonal = 0;
	for (int i = 0; i < BINGO_SIZE; i++) //๋Œ€๊ฐ์„  2๊ฐœ ๋น™๊ณ  ํ™•์ธ
	{
		if (!board[i][i]) right_diagonal++;
		if (!board[i][BINGO_SIZE - i - 1]) left_diagonal++;
	}
	if (right_diagonal == BINGO_SIZE) bingoCnt++;
	if (left_diagonal == BINGO_SIZE) bingoCnt++;

	return bingoCnt;
}

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

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

Copy link
Collaborator

@pu2rile pu2rile 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์ฐจ์› ๋ฐฐ์—ด board ์— ๋ณด๋“œํŒ ์ดˆ๊ธฐํ™”
  2. answer ๋ฐฐ์—ด์— ์‚ฌํšŒ์ž๊ฐ€ ๋ถ€๋ฅด๋Š” ์ˆซ์ž๋ฅผ ์ €์žฅ
  3. ๋ณด๋“œํŒ์—์„œ ์ˆซ์ž๋ฅผ ์ง€์šฐ๋Š” ๋™์ž‘์„ ์ €์žฅํ•˜๋Š” bingo ๋ฐฐ์—ด

์ด๋ ‡๊ฒŒ ๋กœ์ง์„ ์งœ ๋ดค์Šต๋‹ˆ๋‹ค! ์—ฌ๊ธฐ์„œ bingo ๋ฐฐ์—ด์ด visited ๋ฐฐ์—ด๊ณผ ์œ ์‚ฌํ•œ ์„ฑ๊ฒฉ์„ ์ง€๋‹ˆ๊ณ  ์žˆ๋Š” ๊ฒƒ ๊ฐ™๋”๋ผ๊ตฌ์š”??

์ฝ”๋“œ
# ๋น™๊ณ ํŒ ์ดˆ๊ธฐํ™”
board = []
for _ in range(5):
    board.append(list(map(int, input().strip().split())))

# ์‚ฌํšŒ์ž๊ฐ€ ๋ถ€๋ฅด๋Š” ์ˆซ์ž๋“ค ์ดˆ๊ธฐํ™”
answer = []
for _ in range(5):
    answer.append(list(map(int, input().strip().split())))

# ๋น™๊ณ  ์ฒดํฌ๋ฅผ ์œ„ํ•œ ๋ณด๋“œ ์ดˆ๊ธฐํ™” (0์œผ๋กœ ์ดˆ๊ธฐํ™”)
bingo = [[0] * 5 for _ in range(5)]

# ๊ฐ€๋กœ์ค„์„ ์ฒดํฌํ•˜๋Š” ํ•จ์ˆ˜
def check_row():
    res = 0
    for i in range(5):
        cnt = 0
        for j in range(5):
            if bingo[i][j] == 1:
                cnt += 1
        if cnt == 5:
            res += 1
    return res

# ์„ธ๋กœ์ค„์„ ์ฒดํฌํ•˜๋Š” ํ•จ์ˆ˜
def check_col():
    res = 0
    for i in range(5):
        cnt = 0
        for j in range(5):
            if bingo[j][i] == 1:
                cnt += 1
        if cnt == 5:
            res += 1
    return res

# ๋Œ€๊ฐ์„ ์„ ์ฒดํฌํ•˜๋Š” ํ•จ์ˆ˜
def check_dia():
    res = 0
    # ์˜ค๋ฅธ์ชฝ ์œ„์—์„œ ์™ผ์ชฝ ์•„๋ž˜๋กœ ๊ฐ€๋Š” ๋Œ€๊ฐ์„  ์ฒดํฌ
    cnt = 0
    for i in range(5):
        if bingo[i][5 - i - 1] == 1:
            cnt += 1
    if cnt == 5:
        res += 1
    # ์™ผ์ชฝ ์œ„์—์„œ ์˜ค๋ฅธ์ชฝ ์•„๋ž˜๋กœ ๊ฐ€๋Š” ๋Œ€๊ฐ์„  ์ฒดํฌ
    cnt = 0
    for i in range(5):
        if bingo[i][i] == 1:
            cnt += 1
    if cnt == 5:
        res += 1
    return res

# ์‚ฌํšŒ์ž๊ฐ€ ๋ถ€๋ฅธ ์ˆซ์ž๋ฅผ ์ฒดํฌํ•˜๊ณ  ๋น™๊ณ ๋ฅผ ๊ณ„์‚ฐํ•˜๋Š” ๋ถ€๋ถ„
cnt = 0
for i in range(5):
    for j in range(5):
        s = answer[i][j]
        for y in range(5):
            for x in range(5):
                if board[y][x] == s:
                    bingo[y][x] = 1  # ํ•ด๋‹น ์ˆซ์ž๋ฅผ ์ฒดํฌํ•จ
                    cnt = check_row() + check_col() + check_dia()  # ๋น™๊ณ  ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•จ
                    if cnt >= 3:  # 3์ค„ ์ด์ƒ ๋น™๊ณ ๊ฐ€ ๋˜๋ฉด
                        print(i * 5 + j + 1)  # ํ˜„์žฌ ์ˆซ์ž ๋ถ€๋ฅธ ํšŸ์ˆ˜๋ฅผ ์ถœ๋ ฅ
                        exit()  # ํ”„๋กœ๊ทธ๋žจ ์ข…๋ฃŒ

pr ์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค!

@oesnuj oesnuj requested a review from suhyun113 July 7, 2024 07:41
Copy link
Collaborator

@suhyun113 suhyun113 left a comment

Choose a reason for hiding this comment

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

์ด๋ฒˆ์—๋Š” ๋น™๊ณ  ๊ฒŒ์ž„์ด๊ตฐ์š”~ ๋จผ๊ฐ€ ๊ถŒ์˜คํ  ๊ต์ˆ˜๋‹˜ ๊ณผ์ œ๋กœ ํ–ˆ๋˜ ์˜ค์…€๋กœ ๊ฒŒ์ž„, ์˜ค๋ชฉ ๋“ฑ์ด ์ƒ๊ฐ๋‚˜๋Š”,,, ์ €๋Š” ์˜คํžˆ๋ ค ์ด๋Ÿฐ ๊ตฌํ˜„ ๋ฌธ์ œ๋“ค์ด ์–ด๋ ค์šด ๊ฒƒ ๊ฐ™์•„์š”ใ…  ์‹œํ‚ค๋Š” ๋Œ€๋กœ ์ฝ”๋“œ๋ฅผ ์งœ๊ธฐ๋งŒ ํ•˜๋ฉด ๋˜๋Š”๋ฐ... ์—ฐ์Šต์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹คใ… ์ค€์„œ๋‹˜ ์ฝ”๋“œ๋ฅผ ๋ดค๋Š”๋ฐ, ํ•จ์ˆ˜๋ฅผ ์ ์ ˆํžˆ ๋‚˜๋ˆ„์–ด ์ž˜ ๊ตฌํ˜„ํ•˜์‹  ๊ฒƒ ๊ฐ™์•„์š”! ๊ฐ€๋…์„ฑ์ด ์ข‹์•˜์Šต๋‹ˆ๋‹น

checkBingo()ํ•จ์ˆ˜์—์„œ ๊ฐ€๋กœ, ์„ธ๋กœ, ๋Œ€๊ฐ์„  ๋น™๊ณ ๋ฅผ ํ™•์ธํ•˜๋Š” ๋ถ€๋ถ„๋„ ์ฃผ์„์„ ํ†ตํ•ด ์„ค๋ช…ํ•ด์ฃผ์…”์„œ ์ฝ”๋“œ ํ™•์ธ์ด ์‰ฌ์› ์Šต๋‹ˆ๋‹คใ…
๋”ฐ๋กœ ์•Œ์•„๋ณด๋‹ˆ ๋น™๊ณ  ํŒ์˜ ์ƒํƒœ๋ฅผ ์ €์žฅํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ํ˜„์žฌ์˜ 2์ฐจ์› ๋ฐฐ์—ด์ด ์•„๋‹Œ 1์ฐจ์› ๋ฐฐ์—ด์„ ์‚ฌ์šฉํ•˜๋ฉด ๊ณต๊ฐ„์„ ์ ˆ์•ฝํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. 2์ฐจ์› ๋ฐฐ์—ด์€ ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ๋Ÿ‰์ด ํฌ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. ์ œ๊ฐ€ ๋ณด๊ธฐ์—” ์ด๋ฏธ ๊น”๋”ํ•˜๊ฒŒ ์ž˜ ์ž‘์„ฑํ•˜์‹  ๊ฒƒ ๊ฐ™์•„์„œ...ํ  ๋„์›€์ด ๋งŽ์ด ๋ฉ๋‹ˆ๋‹น! ์ €๋„ ๊ตฌํ˜„ ๋ฌธ์ œ ํ•œ ๋ฒˆ ํ’€์–ด๋ด์•ผ๊ฒ ์–ด์š”!
PR ์ˆ˜๊ณ ํ•˜์…จ์–ด์š”~๐Ÿ‘ป

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.

3 participants