Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define ROW 2
- #define COL 3
- int main(void)
- {
- int row, col;
- int i, j;
- int seat[ROW][COL] = { 0 };
- int check = 0;
- while (1)
- {
- printf("좌석을 입력해주세요(행, 열) : ");
- scanf("%d %d", &row, &col);
- check = 0;
- if (seat[row][col] == 0)
- {
- seat[row][col] = 1;
- printf("%d행 %d열에 예약이 되었습니다.\n", row, col);
- check = 1;
- }
- else
- {
- for (j = col + 1;; j++)
- { //!!!
- if (j > COL - 1)
- j = 0;
- if (j == col)
- break;
- if (seat[row][j] == 0)
- {
- seat[row][j] = 1;
- printf("%d행 %d열에 예약이 되었습니다.\n", row, j);
- check = 1;
- break;
- }
- } //v
- if (check == 0)
- {
- for (i = row + 1;; i++)
- {
- check = 0;
- if (i > ROW - 1)
- i = 0;
- if (i == row)
- break;
- for (j = 0; j < COL; j++)
- {
- if (seat[i][j] == 0)
- {
- seat[i][j] = 1;
- printf("%d행 %d열이 예약되었습니다.\n", i, j);
- check = 1;
- break;
- }
- }
- if (check)
- break;
- }
- }
- }
- if (check == 0)
- {
- printf("빈 좌석이 없습니다.\n");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment