|
| 1 | +''' |
| 2 | +Code Up - Algorithm Basic - 100 Questions |
| 3 | +
|
| 4 | +[기초-2차원배열] 1097 Basic Alogrithm question - 2D Array |
| 5 | +https://codeup.kr/problem.php?id=1097 |
| 6 | +
|
| 7 | +Date : 2021-02-18 |
| 8 | +Solved BY : TK Lee |
| 9 | +
|
| 10 | +Young-il, who was waiting for her parents, was playing with black/white go boards stuffed and laid out... |
| 11 | +
|
| 12 | +I thought, "Shall we try to flip the ten (+) character?" |
| 13 | +
|
| 14 | +When all white stones (1) or black stones (0) are placed on the checkerboard (19 * 19), |
| 15 | +Let's write a program that receives n coordinates and outputs the result of flipping the ten (+) characters. |
| 16 | +
|
| 17 | +Reference |
| 18 | +If you use a two-dimensional array that can use horizontal and vertical numbers, |
| 19 | +These forms can be easily recorded and used. Of course, you can also create an extended n-dimensional array. |
| 20 | +
|
| 21 | +
|
| 22 | +example |
| 23 | +int n, i, j, x, y; |
| 24 | +int a[20][20]={}; |
| 25 | +for(i=1; i<=19; i++) //Receive checkerboard status input line by line |
| 26 | + for(j=1; j<=19; j++) |
| 27 | + scanf("%d", &a[i][j]); |
| 28 | +
|
| 29 | +scanf("%d", &n); //Get number of coordinates |
| 30 | +
|
| 31 | +for(i=1; i<=n; i++) //As many as the number of coordinates |
| 32 | +{ |
| 33 | + scanf("%d %d", &x, &y); |
| 34 | + for(j=1; j<=19; j++) // Replace horizontal line black <-> white |
| 35 | + { |
| 36 | + if(a[x][j]==0) a[x][j]=1; |
| 37 | + else a[x][j] = 0; |
| 38 | + } |
| 39 | + for(j=1; j<=19; j++) //replace vertical line black<->white |
| 40 | + { |
| 41 | + if(a[j][y]==0) a[j][y]=1; |
| 42 | + else a[j][y] = 0; |
| 43 | + } |
| 44 | +} |
| 45 | +... |
| 46 | +
|
| 47 | +
|
| 48 | +input |
| 49 | +The situation in which Go eggs are laid is input as an integer value of 19 * 19 size. |
| 50 | +The number of times to flip the cross (n) is input. |
| 51 | +The crosswise flip coordinates are input as many times as n. However, n is a natural number less than 10. |
| 52 | +
|
| 53 | +
|
| 54 | +Print |
| 55 | +Print the result of flipping the cross. |
| 56 | +
|
| 57 | +
|
| 58 | +Input example |
| 59 | +0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 |
| 60 | +0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 |
| 61 | +0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 |
| 62 | +0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 |
| 63 | +0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 |
| 64 | +0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 |
| 65 | +0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 |
| 66 | +0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 |
| 67 | +0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 |
| 68 | +1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 |
| 69 | +0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 |
| 70 | +1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 |
| 71 | +0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 |
| 72 | +0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 |
| 73 | +0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 |
| 74 | +0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 |
| 75 | +0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 |
| 76 | +0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 |
| 77 | +0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 |
| 78 | +2 |
| 79 | +10 10 |
| 80 | +12 12 |
| 81 | +
|
| 82 | +Example output |
| 83 | +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 84 | +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 85 | +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 86 | +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 87 | +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 88 | +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 89 | +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 90 | +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 91 | +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 92 | +0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 |
| 93 | +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 94 | +0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 |
| 95 | +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 96 | +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 97 | +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 98 | +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 99 | +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 100 | +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 101 | +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 102 | +''' |
| 103 | + |
| 104 | +array = [[0 for col in range(19)] for row in range(19)] |
| 105 | + |
| 106 | +for n in range(19): |
| 107 | + array[n] = [int(i) for i in input().split()] |
| 108 | + |
| 109 | +flipCnt = int(input()) |
| 110 | + |
| 111 | +for i in range(0, flipCnt): |
| 112 | + cord = input().split() |
| 113 | + point = list(map(int, cord)) |
| 114 | + x = point[0]-1 |
| 115 | + y = point[1]-1 |
| 116 | + |
| 117 | + for j in range(0, 19): |
| 118 | + if array[x][j] == 0: |
| 119 | + array[x][j] = 1 |
| 120 | + else: |
| 121 | + array[x][j] = 0 |
| 122 | + |
| 123 | + for k in range(0, 19): |
| 124 | + if array[k][y] == 0: |
| 125 | + array[k][y] = 1 |
| 126 | + else: |
| 127 | + array[k][y] = 0 |
| 128 | + |
| 129 | + |
| 130 | +for j in range(19): |
| 131 | + for k in range(19): |
| 132 | + print(array[j][k], end=" ") |
| 133 | + print("") |
0 commit comments