-
[SISS/C언어 스터디] 2학기 9주차 스터디24-2 SISS/C언어 2024. 11. 20. 12:00
2학기 9주차 스터디 백준 제출 내역 화면 캡쳐 자율 2문제를 풀어서 제출하면 됩니다.
언어는 C언어만 가능합니다.
레벨 제한사항: Silver 5 이상
14499
- 구현 → 문제에 주어진 좌표와 이동 방법을 구현한 코드 작성
// 14499.c #include <stdio.h> #define TOP 1 #define BOTTOM 6 int N, M, x, y, K; int board[20][20]; int dx[] = {0, 0, 0, -1, 1}; // x 변화 (동, 서, 북, 남) int dy[] = {0, 1, -1, 0, 0}; // y 변화 (동, 서, 북, 남) int dice[7]; // 주사위 면 int diceFlow[][4] = { {}, {4, 6, 3, 1}, // 동 -> 1 {1, 3, 6, 4}, // 서 -> 2 {6, 5, 1, 2}, // 북 -> 3 {2, 1, 5, 6} // 남 -> 4 }; // 주사위 이동 가능 여부 확인 int moveDice(int dir) { int nx = x + dx[dir]; int ny = y + dy[dir]; if (nx < 0 || nx >= N || ny < 0 || ny >= M) { return 0; // 이동 불가 } x = nx; y = ny; return 1; // 이동 가능 } // 주사위를 굴리기 void rollDice(int dir) { int tmp = dice[diceFlow[dir][3]]; for (int i = 3; i > 0; i--) { dice[diceFlow[dir][i]] = dice[diceFlow[dir][i - 1]]; } dice[diceFlow[dir][0]] = tmp; } // 주사위 바닥 면 복사 void copyBottom() { if (board[x][y]) { dice[BOTTOM] = board[x][y]; board[x][y] = 0; } else { board[x][y] = dice[BOTTOM]; } } int main() { scanf("%d %d %d %d %d", &N, &M, &x, &y, &K); for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { scanf("%d", &board[i][j]); } } while (K--) { int dir; scanf("%d", &dir); if (!moveDice(dir)) { continue; // 이동 불가의 경우 넘어감 } rollDice(dir); copyBottom(); printf("%d\n", dice[TOP]); // 주사위 윗면 출력 } return 0; }
2527
- 기하학 → 만나지 않는 경우, 점에서 만나는 경우, 변으로 만나는 경우, 면으로 만나는 경우의 네 가지를 작성
// 2527.c #include <stdio.h> int main() { for (int i = 0; i < 4; i++) { int x1, y1, p1, q1, x2, y2, p2, q2; // 입력 scanf("%d %d %d %d %d %d %d %d", &x1, &y1, &p1, &q1, &x2, &y2, &p2, &q2); // 만나지 않는 경우 if (p1 < x2 || p2 < x1 || y1 > q2 || q1 < y2) { printf("d\n"); continue; } // 한 점에서 만나는 경우 else if ((x1 == p2 || x2 == p1) && (q1 == y2 || q2 == y1)) { printf("c\n"); continue; } // 변이 만나는 경우 else if (x1 == p2 || x2 == p1 || q1 == y2 || q2 == y1) { printf("b\n"); continue; } // 나머지 (면이 겹치는 경우) else { printf("a\n"); continue; } } return 0; }
'24-2 SISS > C언어' 카테고리의 다른 글
[SISS/C언어 스터디] 2학기 8주차 스터디 (0) 2024.11.16 [SISS/C언어 스터디] 2학기 7주차 스터디 (0) 2024.11.10 [SISS/C언어 스터디] 2학기 6주차 스터디 (2) 2024.11.03 [SISS/C언어 스터디] 2학기 5주차 스터디 (1) 2024.10.06 [SISS/C언어 스터디] 2학기 4주차 스터디 (1) 2024.09.29