From dafff9e6e6f9c56537ab403cdb18256b06f2f691 Mon Sep 17 00:00:00 2001 From: kkanazawa Date: Fri, 4 Jul 2025 16:44:21 +0900 Subject: [PATCH 1/6] =?UTF-8?q?paiza=E3=81=AE=E5=95=8F=E9=A1=8CB138?= =?UTF-8?q?=E3=81=AE=E5=9B=9E=E7=AD=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kkanazawa/src/SpiralDecoder.java | 190 +++++++++++++++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 kkanazawa/src/SpiralDecoder.java diff --git a/kkanazawa/src/SpiralDecoder.java b/kkanazawa/src/SpiralDecoder.java new file mode 100644 index 0000000..8ecb5e8 --- /dev/null +++ b/kkanazawa/src/SpiralDecoder.java @@ -0,0 +1,190 @@ +package paiza.src; + +import java.lang.reflect.Array; +import java.util.Scanner; + +/** + * 受け取った二次元の文字リストをうずまき型で解読する + * + * @author 金澤継心 + */ +public class SpiralDecoder { + + public static void main(final String[] args) { + Scanner scanner = new Scanner(System.in); + final int lineAmount = scanner.nextInt(); // 入力値の行の数 + final int columnAmount = scanner.nextInt(); // 入力値の列の数; + final int startIndex = scanner.nextInt(); // 読み始まる文字のインデックス + final int endIndex = scanner.nextInt(); // 読み終える文字のインデックス + + // もととなる二次元の文字リストのを入力から受け取る + final String[][] cipher = inputCipher(scanner, lineAmount, columnAmount); + scanner.close(); + + // 入力値の二次元の文字リストの周りをNULLで埋める + final String[][] paddedCipher = nullPaddingCipher(cipher); + // 復号処理 + final String selectedDecode = decodingCipher(lineAmount, columnAmount, startIndex, endIndex, + paddedCipher); + System.out.println(selectedDecode); + } + + /** + * もととなる文字列を入力から受け取る + * + * @param scanner 入力を受け取るスキャナー + * @param lineAmount 文字リストの行数 + * @param columnAmount 文字リストの列数 + */ + public static String[][] inputCipher(final Scanner scanner, final int lineAmount, final int columnAmount) { + String[][] cipher = new String[lineAmount][columnAmount]; + for (int i = 0; i < lineAmount; i++) { + String inputLine = scanner.next(); + cipher[i] = inputLine.split(""); + } + return cipher; + } + + /** + * 文字リストの周りをNULLで埋める + * + * @param originCipher もととなる文字リスト + */ + public static String[][] nullPaddingCipher(final String[][] originCipher) { + final int lineAmount = Array.getLength(originCipher); + final int columnAmount = Array.getLength(originCipher[0]); + String[][] paddedCipher = new String[lineAmount + 2][columnAmount + 2]; + + // 元の文字リストをNULLしかない文字リストの中央にコピーする + for (int i = 0; i < lineAmount; i++) { + System.arraycopy(originCipher[i], 0, paddedCipher[i + 1], 1, columnAmount); + } + return paddedCipher; + } + + /** + * 周りをNULLで埋めた文字リストの解読 NULLにぶつかったら方向転換するイメージでうずまき状に要素を移動する + * 移動した順に要素を復号用の配列に移していき、元の配列の要素はNULLに置き換える + * + * @param lineAmount 文字列リストの行数 + * @param columnAmount 文字列リストの列数 + * @param startIndex 解読後読み始める文字の順番 + * @param endIndex 解読後読み終える文字の順番 + */ + public static String decodingCipher(final int lineAmount, final int columnAmount, final int startIndex, + final int endIndex, final String[][] cipher) { + // 現在いる要素を示すカーソルとして使うクラス + DecodeCursor cursor = new DecodeCursor(); + // NULLでかこっているため、始まりのインデックスは行、列ともに1から + cursor.setLineIndex(1); + cursor.setColumnIndex(1); + // 移動する方向を表すインスタンス変数 + cursor.setDirection(0); + // 現在移し終えた文字数のカウンタ + int charCounter = 0; + // この配列に文字移して最終的には復号した順番に文字が並ぶ + String[] decordResult = new String[lineAmount * columnAmount]; + + while (charCounter < lineAmount * columnAmount) { + // NULLの要素に移動した際、カーソルの位置を戻す処理 + cursor.modifying(charCounter); + // NULLのぶつかるまで一方向に要素を読み取り続ける + while (cipher[cursor.getLineIndex()][cursor.getColumnIndex()] != null) { + decordResult[charCounter] = cipher[cursor.getLineIndex()][cursor.getColumnIndex()]; + cipher[cursor.getLineIndex()][cursor.getColumnIndex()] = null; + charCounter++; + // カーソルを現在進むべき方向に移動させる + cursor.shifting(); + } + // 方向転換の処理 + cursor.changeDirection(); + } + return String.join("", decordResult).substring(startIndex - 1, endIndex); + } + +} + + +/** + * 現在読み取っている要素を示すカーソルとして使うクラス + * + */ +class DecodeCursor { + private int direction;// 方向を示す 4つの方向はこの値を4で割った剰余として区別している + private int lineIndex;// 現在の行の位置 + private int columnIndex;// 現在の列の位置 + + public int getDirection() { + return direction; + } + + public void setDirection(int direction) { + this.direction = direction; + } + + public void changeDirection() { + this.direction++; + } + + public int getLineIndex() { + return lineIndex; + } + + public void setLineIndex(int lineIndex) { + this.lineIndex = lineIndex; + } + + public int getColumnIndex() { + return columnIndex; + } + + public void setColumnIndex(int columnIndex) { + this.columnIndex = columnIndex; + } + + // NULLの要素に移動した際、カーソルの位置を戻す処理 + // 4つの方向はdirectionを4で割った剰余として区別している + // 0:右 1:下 2:左 3:上 + public void modifying(final int charCounter) { + switch (direction % 4) { + case 0: + if (charCounter != 0) { + this.columnIndex++; + this.lineIndex++; + } + break; + case 1: + this.columnIndex--; + this.lineIndex++; + break; + case 2: + this.columnIndex--; + this.lineIndex--; + break; + case 3: + this.columnIndex++; + this.lineIndex--; + break; + } + } + + // カーソルを現在進むべき方向に移動させる + // 4つの方向はdirectionを4で割った剰余として区別している + // 0:右 1:下 2:左 3:上 + public void shifting() { + switch (this.direction % 4) { + case 0: + this.columnIndex++; + break; + case 1: + this.lineIndex++; + break; + case 2: + this.columnIndex--; + break; + case 3: + this.lineIndex--; + break; + } + } +} -- GitLab From a9235b5fba8dc52b4e5898f3b0a88d08a4ef01d8 Mon Sep 17 00:00:00 2001 From: kkanazawa Date: Mon, 7 Jul 2025 16:04:29 +0900 Subject: [PATCH 2/6] =?UTF-8?q?paiza=E3=81=AE=E5=95=8F=E9=A1=8CB156?= =?UTF-8?q?=E3=81=AE=E5=9B=9E=E7=AD=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kkanazawa/src/SpiralDecoder.java | 181 ++++++++++++++++++------------- 1 file changed, 105 insertions(+), 76 deletions(-) diff --git a/kkanazawa/src/SpiralDecoder.java b/kkanazawa/src/SpiralDecoder.java index 8ecb5e8..be0dc1b 100644 --- a/kkanazawa/src/SpiralDecoder.java +++ b/kkanazawa/src/SpiralDecoder.java @@ -1,6 +1,7 @@ package paiza.src; import java.lang.reflect.Array; +import java.util.Arrays; import java.util.Scanner; /** @@ -12,86 +13,104 @@ public class SpiralDecoder { public static void main(final String[] args) { Scanner scanner = new Scanner(System.in); - final int lineAmount = scanner.nextInt(); // 入力値の行の数 - final int columnAmount = scanner.nextInt(); // 入力値の列の数; - final int startIndex = scanner.nextInt(); // 読み始まる文字のインデックス - final int endIndex = scanner.nextInt(); // 読み終える文字のインデックス + final int ROW_COUNT = scanner.nextInt(); // 入力値の行の数 + final int COLUMN_COUNT = scanner.nextInt(); // 入力値の列の数; + final int START_INDEX = scanner.nextInt(); // 読み始まる文字のインデックス + final int END_INDEX = scanner.nextInt(); // 読み終える文字のインデックス + final String BARRIR_CHAR = "@"; // もととなる二次元の文字リストのを入力から受け取る - final String[][] cipher = inputCipher(scanner, lineAmount, columnAmount); + final String[][] CIPHER = inputCipher(scanner, ROW_COUNT, COLUMN_COUNT); scanner.close(); // 入力値の二次元の文字リストの周りをNULLで埋める - final String[][] paddedCipher = nullPaddingCipher(cipher); - // 復号処理 - final String selectedDecode = decodingCipher(lineAmount, columnAmount, startIndex, endIndex, - paddedCipher); + final String[][] PADDED_CIPHER = paddingCipher(CIPHER, BARRIR_CHAR); + + // 解読処理 + final String selectedDecode = decodingCipher(ROW_COUNT, COLUMN_COUNT, START_INDEX, END_INDEX, + PADDED_CIPHER, BARRIR_CHAR); System.out.println(selectedDecode); } /** * もととなる文字列を入力から受け取る * - * @param scanner 入力を受け取るスキャナー - * @param lineAmount 文字リストの行数 - * @param columnAmount 文字リストの列数 + * @param SCANNER 入力を受け取るスキャナー + * @param ROW_COUNT 文字リストの行数 + * @param COLUMN_COUNT 文字リストの列数 */ - public static String[][] inputCipher(final Scanner scanner, final int lineAmount, final int columnAmount) { - String[][] cipher = new String[lineAmount][columnAmount]; - for (int i = 0; i < lineAmount; i++) { - String inputLine = scanner.next(); - cipher[i] = inputLine.split(""); + public static String[][] inputCipher(final Scanner SCANNER, final int ROW_COUNT, + final int COLUMN_COUNT) { + String[][] cipher = new String[ROW_COUNT][COLUMN_COUNT]; + for (int i = 0; i < ROW_COUNT; i++) { + String inputRow = SCANNER.next(); + cipher[i] = inputRow.split(""); } return cipher; } /** - * 文字リストの周りをNULLで埋める + * 文字リストの周りを@で埋める * - * @param originCipher もととなる文字リスト + * @param ORIGIN_CIPHER もととなる文字リスト */ - public static String[][] nullPaddingCipher(final String[][] originCipher) { - final int lineAmount = Array.getLength(originCipher); - final int columnAmount = Array.getLength(originCipher[0]); - String[][] paddedCipher = new String[lineAmount + 2][columnAmount + 2]; - - // 元の文字リストをNULLしかない文字リストの中央にコピーする - for (int i = 0; i < lineAmount; i++) { - System.arraycopy(originCipher[i], 0, paddedCipher[i + 1], 1, columnAmount); + public static String[][] paddingCipher(final String[][] ORIGIN_CIPHER, final String BARRIR_CHAR) { + final int ROW_COUNT = Array.getLength(ORIGIN_CIPHER); + final int COLUMN_COUNT = Array.getLength(ORIGIN_CIPHER[0]); + String[][] paddedCipher = new String[ROW_COUNT + 2][COLUMN_COUNT + 2]; + + for (String[] o : paddedCipher) { + Arrays.fill(o, BARRIR_CHAR); + } + + // 元の文字リストを"@"しかない文字リストの中央にコピーする + for (int i = 0; i < ROW_COUNT; i++) { + System.arraycopy(ORIGIN_CIPHER[i], 0, paddedCipher[i + 1], 1, COLUMN_COUNT); } return paddedCipher; } /** - * 周りをNULLで埋めた文字リストの解読 NULLにぶつかったら方向転換するイメージでうずまき状に要素を移動する + * 周りをNULLで埋めた文字リストの解読 @にぶつかったら方向転換するイメージでうずまき状に要素を移動する * 移動した順に要素を復号用の配列に移していき、元の配列の要素はNULLに置き換える * - * @param lineAmount 文字列リストの行数 - * @param columnAmount 文字列リストの列数 - * @param startIndex 解読後読み始める文字の順番 - * @param endIndex 解読後読み終える文字の順番 + * @param ROW_COUNT 文字列リストの行数 + * @param COLUMN_COUNT 文字列リストの列数 + * @param START_INDEX 解読後読み始める文字の順番 + * @param END_INDEX 解読後読み終える文字の順番 */ - public static String decodingCipher(final int lineAmount, final int columnAmount, final int startIndex, - final int endIndex, final String[][] cipher) { + public static String decodingCipher(final int ROW_COUNT, final int COLUMN_COUNT, + final int START_INDEX, + final int END_INDEX, final String[][] CIPHER, final String BARRIR_CHAR) { // 現在いる要素を示すカーソルとして使うクラス DecodeCursor cursor = new DecodeCursor(); // NULLでかこっているため、始まりのインデックスは行、列ともに1から - cursor.setLineIndex(1); + cursor.setRowIndex(1); cursor.setColumnIndex(1); // 移動する方向を表すインスタンス変数 cursor.setDirection(0); // 現在移し終えた文字数のカウンタ int charCounter = 0; // この配列に文字移して最終的には復号した順番に文字が並ぶ - String[] decordResult = new String[lineAmount * columnAmount]; - - while (charCounter < lineAmount * columnAmount) { - // NULLの要素に移動した際、カーソルの位置を戻す処理 - cursor.modifying(charCounter); - // NULLのぶつかるまで一方向に要素を読み取り続ける - while (cipher[cursor.getLineIndex()][cursor.getColumnIndex()] != null) { - decordResult[charCounter] = cipher[cursor.getLineIndex()][cursor.getColumnIndex()]; - cipher[cursor.getLineIndex()][cursor.getColumnIndex()] = null; + String[] decodedResult = new String[ROW_COUNT * COLUMN_COUNT]; + + // 初期位置から初めて@にぶつかるまでの解読処理 + while (CIPHER[cursor.getRowIndex()][cursor.getColumnIndex()] != BARRIR_CHAR) { + decodedResult[charCounter] = CIPHER[cursor.getRowIndex()][cursor.getColumnIndex()]; + CIPHER[cursor.getRowIndex()][cursor.getColumnIndex()] = BARRIR_CHAR; + charCounter++; + cursor.shifting(); + } + cursor.changeDirection(); + + // 初めて@にぶつかってから解読し終わるまでの処理 + while (charCounter < ROW_COUNT * COLUMN_COUNT) { + // @の要素に移動した際、カーソルの位置を戻す処理 + cursor.modifying(); + // @のぶつかるまで一方向に要素を読み取り続ける + while (CIPHER[cursor.getRowIndex()][cursor.getColumnIndex()] != BARRIR_CHAR) { + decodedResult[charCounter] = CIPHER[cursor.getRowIndex()][cursor.getColumnIndex()]; + CIPHER[cursor.getRowIndex()][cursor.getColumnIndex()] = BARRIR_CHAR; charCounter++; // カーソルを現在進むべき方向に移動させる cursor.shifting(); @@ -99,7 +118,7 @@ public class SpiralDecoder { // 方向転換の処理 cursor.changeDirection(); } - return String.join("", decordResult).substring(startIndex - 1, endIndex); + return String.join("", decodedResult).substring(START_INDEX - 1, END_INDEX); } } @@ -111,59 +130,63 @@ public class SpiralDecoder { */ class DecodeCursor { private int direction;// 方向を示す 4つの方向はこの値を4で割った剰余として区別している - private int lineIndex;// 現在の行の位置 + private int rowIndex;// 現在の行の位置 private int columnIndex;// 現在の列の位置 public int getDirection() { return direction; } - public void setDirection(int direction) { - this.direction = direction; + public void setDirection(final int DIRECTION) { + this.direction = DIRECTION; } public void changeDirection() { this.direction++; } - public int getLineIndex() { - return lineIndex; + public int getRowIndex() { + return rowIndex; } - public void setLineIndex(int lineIndex) { - this.lineIndex = lineIndex; + public void setRowIndex(final int ROW_INDEX) { + this.rowIndex = ROW_INDEX; } public int getColumnIndex() { return columnIndex; } - public void setColumnIndex(int columnIndex) { - this.columnIndex = columnIndex; + public void setColumnIndex(final int COLUMN_INDEX) { + this.columnIndex = COLUMN_INDEX; } - // NULLの要素に移動した際、カーソルの位置を戻す処理 - // 4つの方向はdirectionを4で割った剰余として区別している + // NULL(要検討)の要素に移動した際、カーソルの位置を戻す処理 + // 4つの方向はdirectionを4で割った剰余として区別する // 0:右 1:下 2:左 3:上 - public void modifying(final int charCounter) { - switch (direction % 4) { - case 0: - if (charCounter != 0) { - this.columnIndex++; - this.lineIndex++; - } + public void modifying() { + final int DIRECTION_NUM = this.direction % 4; + final int RIGHT_NUM = 0; + final int DOWN_NUM = 1; + final int LEFT_NUM = 2; + final int UP_NUM = 3; + + switch (DIRECTION_NUM) { + case RIGHT_NUM: + this.columnIndex++; + this.rowIndex++; break; - case 1: + case DOWN_NUM: this.columnIndex--; - this.lineIndex++; + this.rowIndex++; break; - case 2: + case LEFT_NUM: this.columnIndex--; - this.lineIndex--; + this.rowIndex--; break; - case 3: + case UP_NUM: this.columnIndex++; - this.lineIndex--; + this.rowIndex--; break; } } @@ -172,18 +195,24 @@ class DecodeCursor { // 4つの方向はdirectionを4で割った剰余として区別している // 0:右 1:下 2:左 3:上 public void shifting() { - switch (this.direction % 4) { - case 0: + final int DIRECTION_NUM = this.direction % 4; + final int RIGHT_NUM = 0; + final int DOWN_NUM = 1; + final int LEFT_NUM = 2; + final int UP_NUM = 3; + + switch (DIRECTION_NUM) { + case RIGHT_NUM: this.columnIndex++; break; - case 1: - this.lineIndex++; + case DOWN_NUM: + this.rowIndex++; break; - case 2: + case LEFT_NUM: this.columnIndex--; break; - case 3: - this.lineIndex--; + case UP_NUM: + this.rowIndex--; break; } } -- GitLab From cad12ab177baec88577281987f99500f6fe0c6b4 Mon Sep 17 00:00:00 2001 From: kkanazawa Date: Mon, 7 Jul 2025 17:44:16 +0900 Subject: [PATCH 3/6] =?UTF-8?q?paiza=E3=81=AE=E5=95=8F=E9=A1=8CB156?= =?UTF-8?q?=E3=81=AE=E5=9B=9E=E7=AD=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kkanazawa/src/SpiralDecoder.java | 119 +++++++++++++++---------------- 1 file changed, 58 insertions(+), 61 deletions(-) diff --git a/kkanazawa/src/SpiralDecoder.java b/kkanazawa/src/SpiralDecoder.java index be0dc1b..45c2046 100644 --- a/kkanazawa/src/SpiralDecoder.java +++ b/kkanazawa/src/SpiralDecoder.java @@ -13,37 +13,37 @@ public class SpiralDecoder { public static void main(final String[] args) { Scanner scanner = new Scanner(System.in); - final int ROW_COUNT = scanner.nextInt(); // 入力値の行の数 - final int COLUMN_COUNT = scanner.nextInt(); // 入力値の列の数; - final int START_INDEX = scanner.nextInt(); // 読み始まる文字のインデックス - final int END_INDEX = scanner.nextInt(); // 読み終える文字のインデックス - final String BARRIR_CHAR = "@"; + final int rowCount = scanner.nextInt(); // 入力値の行の数 + final int columnCount = scanner.nextInt(); // 入力値の列の数; + final int startIndex = scanner.nextInt(); // 読み始まる文字のインデックス + final int endIndex = scanner.nextInt(); // 読み終える文字のインデックス + final String barrirchar = "@"; // もととなる二次元の文字リストのを入力から受け取る - final String[][] CIPHER = inputCipher(scanner, ROW_COUNT, COLUMN_COUNT); + final String[][] cipher = inputCipher(scanner, rowCount, columnCount); scanner.close(); // 入力値の二次元の文字リストの周りをNULLで埋める - final String[][] PADDED_CIPHER = paddingCipher(CIPHER, BARRIR_CHAR); + final String[][] paddedCipher = paddingCipher(cipher, barrirchar); // 解読処理 - final String selectedDecode = decodingCipher(ROW_COUNT, COLUMN_COUNT, START_INDEX, END_INDEX, - PADDED_CIPHER, BARRIR_CHAR); + final String selectedDecode = decodingCipher(rowCount, columnCount, startIndex, endIndex, + paddedCipher, barrirchar); System.out.println(selectedDecode); } /** * もととなる文字列を入力から受け取る * - * @param SCANNER 入力を受け取るスキャナー - * @param ROW_COUNT 文字リストの行数 - * @param COLUMN_COUNT 文字リストの列数 + * @param scanner 入力を受け取るスキャナー + * @param rowCount 文字リストの行数 + * @param columnCount 文字リストの列数 */ - public static String[][] inputCipher(final Scanner SCANNER, final int ROW_COUNT, - final int COLUMN_COUNT) { - String[][] cipher = new String[ROW_COUNT][COLUMN_COUNT]; - for (int i = 0; i < ROW_COUNT; i++) { - String inputRow = SCANNER.next(); + public static String[][] inputCipher(final Scanner scanner, final int rowCount, + final int columnCount) { + String[][] cipher = new String[rowCount][columnCount]; + for (int i = 0; i < rowCount; i++) { + String inputRow = scanner.next(); cipher[i] = inputRow.split(""); } return cipher; @@ -52,20 +52,20 @@ public class SpiralDecoder { /** * 文字リストの周りを@で埋める * - * @param ORIGIN_CIPHER もととなる文字リスト + * @param originCipher もととなる文字リスト */ - public static String[][] paddingCipher(final String[][] ORIGIN_CIPHER, final String BARRIR_CHAR) { - final int ROW_COUNT = Array.getLength(ORIGIN_CIPHER); - final int COLUMN_COUNT = Array.getLength(ORIGIN_CIPHER[0]); + public static String[][] paddingCipher(final String[][] originCipher, final String barrirchar) { + final int ROW_COUNT = Array.getLength(originCipher); + final int COLUMN_COUNT = Array.getLength(originCipher[0]); String[][] paddedCipher = new String[ROW_COUNT + 2][COLUMN_COUNT + 2]; for (String[] o : paddedCipher) { - Arrays.fill(o, BARRIR_CHAR); + Arrays.fill(o, barrirchar); } // 元の文字リストを"@"しかない文字リストの中央にコピーする for (int i = 0; i < ROW_COUNT; i++) { - System.arraycopy(ORIGIN_CIPHER[i], 0, paddedCipher[i + 1], 1, COLUMN_COUNT); + System.arraycopy(originCipher[i], 0, paddedCipher[i + 1], 1, COLUMN_COUNT); } return paddedCipher; } @@ -74,14 +74,14 @@ public class SpiralDecoder { * 周りをNULLで埋めた文字リストの解読 @にぶつかったら方向転換するイメージでうずまき状に要素を移動する * 移動した順に要素を復号用の配列に移していき、元の配列の要素はNULLに置き換える * - * @param ROW_COUNT 文字列リストの行数 - * @param COLUMN_COUNT 文字列リストの列数 - * @param START_INDEX 解読後読み始める文字の順番 - * @param END_INDEX 解読後読み終える文字の順番 + * @param rowCount 文字列リストの行数 + * @param columnCount 文字列リストの列数 + * @param startIndex 解読後読み始める文字の順番 + * @param endIndex 解読後読み終える文字の順番 */ - public static String decodingCipher(final int ROW_COUNT, final int COLUMN_COUNT, - final int START_INDEX, - final int END_INDEX, final String[][] CIPHER, final String BARRIR_CHAR) { + public static String decodingCipher(final int rowCount, final int columnCount, + final int startIndex, + final int endIndex, final String[][] cipher, final String barrirchar) { // 現在いる要素を示すカーソルとして使うクラス DecodeCursor cursor = new DecodeCursor(); // NULLでかこっているため、始まりのインデックスは行、列ともに1から @@ -92,25 +92,25 @@ public class SpiralDecoder { // 現在移し終えた文字数のカウンタ int charCounter = 0; // この配列に文字移して最終的には復号した順番に文字が並ぶ - String[] decodedResult = new String[ROW_COUNT * COLUMN_COUNT]; + String[] decodedResult = new String[rowCount * columnCount]; // 初期位置から初めて@にぶつかるまでの解読処理 - while (CIPHER[cursor.getRowIndex()][cursor.getColumnIndex()] != BARRIR_CHAR) { - decodedResult[charCounter] = CIPHER[cursor.getRowIndex()][cursor.getColumnIndex()]; - CIPHER[cursor.getRowIndex()][cursor.getColumnIndex()] = BARRIR_CHAR; + while (cipher[cursor.getRowIndex()][cursor.getColumnIndex()] != barrirchar) { + decodedResult[charCounter] = cipher[cursor.getRowIndex()][cursor.getColumnIndex()]; + cipher[cursor.getRowIndex()][cursor.getColumnIndex()] = barrirchar; charCounter++; cursor.shifting(); } cursor.changeDirection(); // 初めて@にぶつかってから解読し終わるまでの処理 - while (charCounter < ROW_COUNT * COLUMN_COUNT) { + while (charCounter < rowCount * columnCount) { // @の要素に移動した際、カーソルの位置を戻す処理 cursor.modifying(); // @のぶつかるまで一方向に要素を読み取り続ける - while (CIPHER[cursor.getRowIndex()][cursor.getColumnIndex()] != BARRIR_CHAR) { - decodedResult[charCounter] = CIPHER[cursor.getRowIndex()][cursor.getColumnIndex()]; - CIPHER[cursor.getRowIndex()][cursor.getColumnIndex()] = BARRIR_CHAR; + while (cipher[cursor.getRowIndex()][cursor.getColumnIndex()] != barrirchar) { + decodedResult[charCounter] = cipher[cursor.getRowIndex()][cursor.getColumnIndex()]; + cipher[cursor.getRowIndex()][cursor.getColumnIndex()] = barrirchar; charCounter++; // カーソルを現在進むべき方向に移動させる cursor.shifting(); @@ -118,7 +118,7 @@ public class SpiralDecoder { // 方向転換の処理 cursor.changeDirection(); } - return String.join("", decodedResult).substring(START_INDEX - 1, END_INDEX); + return String.join("", decodedResult).substring(startIndex - 1, endIndex); } } @@ -132,6 +132,10 @@ class DecodeCursor { private int direction;// 方向を示す 4つの方向はこの値を4で割った剰余として区別している private int rowIndex;// 現在の行の位置 private int columnIndex;// 現在の列の位置 + final static int RIGHT = 0; + final static int DOWN = 1; + final static int LEFT = 2; + final static int UP = 3; public int getDirection() { return direction; @@ -165,26 +169,22 @@ class DecodeCursor { // 4つの方向はdirectionを4で割った剰余として区別する // 0:右 1:下 2:左 3:上 public void modifying() { - final int DIRECTION_NUM = this.direction % 4; - final int RIGHT_NUM = 0; - final int DOWN_NUM = 1; - final int LEFT_NUM = 2; - final int UP_NUM = 3; - - switch (DIRECTION_NUM) { - case RIGHT_NUM: + final int directionNum = this.direction % 4; + + switch (directionNum) { + case RIGHT: this.columnIndex++; this.rowIndex++; break; - case DOWN_NUM: + case DOWN: this.columnIndex--; this.rowIndex++; break; - case LEFT_NUM: + case LEFT: this.columnIndex--; this.rowIndex--; break; - case UP_NUM: + case UP: this.columnIndex++; this.rowIndex--; break; @@ -195,23 +195,20 @@ class DecodeCursor { // 4つの方向はdirectionを4で割った剰余として区別している // 0:右 1:下 2:左 3:上 public void shifting() { - final int DIRECTION_NUM = this.direction % 4; - final int RIGHT_NUM = 0; - final int DOWN_NUM = 1; - final int LEFT_NUM = 2; - final int UP_NUM = 3; - - switch (DIRECTION_NUM) { - case RIGHT_NUM: + final int directionNum= this.direction % 4; + + + switch (directionNum) { + case RIGHT: this.columnIndex++; break; - case DOWN_NUM: + case DOWN: this.rowIndex++; break; - case LEFT_NUM: + case LEFT: this.columnIndex--; break; - case UP_NUM: + case UP: this.rowIndex--; break; } -- GitLab From 72ac6f64abff7648a28da76d14f4de58c3780580 Mon Sep 17 00:00:00 2001 From: kkanazawa Date: Tue, 8 Jul 2025 15:55:56 +0900 Subject: [PATCH 4/6] =?UTF-8?q?paiza=E3=81=AE=E5=95=8F=E9=A1=8CB128?= =?UTF-8?q?=E3=81=AE=E5=9B=9E=E7=AD=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kkanazawa/src/SpiralDecoder.java | 216 ------------------ .../src/TwoDimensionBarcodeConversion.java | 173 ++++++++++++++ 2 files changed, 173 insertions(+), 216 deletions(-) delete mode 100644 kkanazawa/src/SpiralDecoder.java create mode 100644 kkanazawa/src/TwoDimensionBarcodeConversion.java diff --git a/kkanazawa/src/SpiralDecoder.java b/kkanazawa/src/SpiralDecoder.java deleted file mode 100644 index 45c2046..0000000 --- a/kkanazawa/src/SpiralDecoder.java +++ /dev/null @@ -1,216 +0,0 @@ -package paiza.src; - -import java.lang.reflect.Array; -import java.util.Arrays; -import java.util.Scanner; - -/** - * 受け取った二次元の文字リストをうずまき型で解読する - * - * @author 金澤継心 - */ -public class SpiralDecoder { - - public static void main(final String[] args) { - Scanner scanner = new Scanner(System.in); - final int rowCount = scanner.nextInt(); // 入力値の行の数 - final int columnCount = scanner.nextInt(); // 入力値の列の数; - final int startIndex = scanner.nextInt(); // 読み始まる文字のインデックス - final int endIndex = scanner.nextInt(); // 読み終える文字のインデックス - final String barrirchar = "@"; - - // もととなる二次元の文字リストのを入力から受け取る - final String[][] cipher = inputCipher(scanner, rowCount, columnCount); - scanner.close(); - - // 入力値の二次元の文字リストの周りをNULLで埋める - final String[][] paddedCipher = paddingCipher(cipher, barrirchar); - - // 解読処理 - final String selectedDecode = decodingCipher(rowCount, columnCount, startIndex, endIndex, - paddedCipher, barrirchar); - System.out.println(selectedDecode); - } - - /** - * もととなる文字列を入力から受け取る - * - * @param scanner 入力を受け取るスキャナー - * @param rowCount 文字リストの行数 - * @param columnCount 文字リストの列数 - */ - public static String[][] inputCipher(final Scanner scanner, final int rowCount, - final int columnCount) { - String[][] cipher = new String[rowCount][columnCount]; - for (int i = 0; i < rowCount; i++) { - String inputRow = scanner.next(); - cipher[i] = inputRow.split(""); - } - return cipher; - } - - /** - * 文字リストの周りを@で埋める - * - * @param originCipher もととなる文字リスト - */ - public static String[][] paddingCipher(final String[][] originCipher, final String barrirchar) { - final int ROW_COUNT = Array.getLength(originCipher); - final int COLUMN_COUNT = Array.getLength(originCipher[0]); - String[][] paddedCipher = new String[ROW_COUNT + 2][COLUMN_COUNT + 2]; - - for (String[] o : paddedCipher) { - Arrays.fill(o, barrirchar); - } - - // 元の文字リストを"@"しかない文字リストの中央にコピーする - for (int i = 0; i < ROW_COUNT; i++) { - System.arraycopy(originCipher[i], 0, paddedCipher[i + 1], 1, COLUMN_COUNT); - } - return paddedCipher; - } - - /** - * 周りをNULLで埋めた文字リストの解読 @にぶつかったら方向転換するイメージでうずまき状に要素を移動する - * 移動した順に要素を復号用の配列に移していき、元の配列の要素はNULLに置き換える - * - * @param rowCount 文字列リストの行数 - * @param columnCount 文字列リストの列数 - * @param startIndex 解読後読み始める文字の順番 - * @param endIndex 解読後読み終える文字の順番 - */ - public static String decodingCipher(final int rowCount, final int columnCount, - final int startIndex, - final int endIndex, final String[][] cipher, final String barrirchar) { - // 現在いる要素を示すカーソルとして使うクラス - DecodeCursor cursor = new DecodeCursor(); - // NULLでかこっているため、始まりのインデックスは行、列ともに1から - cursor.setRowIndex(1); - cursor.setColumnIndex(1); - // 移動する方向を表すインスタンス変数 - cursor.setDirection(0); - // 現在移し終えた文字数のカウンタ - int charCounter = 0; - // この配列に文字移して最終的には復号した順番に文字が並ぶ - String[] decodedResult = new String[rowCount * columnCount]; - - // 初期位置から初めて@にぶつかるまでの解読処理 - while (cipher[cursor.getRowIndex()][cursor.getColumnIndex()] != barrirchar) { - decodedResult[charCounter] = cipher[cursor.getRowIndex()][cursor.getColumnIndex()]; - cipher[cursor.getRowIndex()][cursor.getColumnIndex()] = barrirchar; - charCounter++; - cursor.shifting(); - } - cursor.changeDirection(); - - // 初めて@にぶつかってから解読し終わるまでの処理 - while (charCounter < rowCount * columnCount) { - // @の要素に移動した際、カーソルの位置を戻す処理 - cursor.modifying(); - // @のぶつかるまで一方向に要素を読み取り続ける - while (cipher[cursor.getRowIndex()][cursor.getColumnIndex()] != barrirchar) { - decodedResult[charCounter] = cipher[cursor.getRowIndex()][cursor.getColumnIndex()]; - cipher[cursor.getRowIndex()][cursor.getColumnIndex()] = barrirchar; - charCounter++; - // カーソルを現在進むべき方向に移動させる - cursor.shifting(); - } - // 方向転換の処理 - cursor.changeDirection(); - } - return String.join("", decodedResult).substring(startIndex - 1, endIndex); - } - -} - - -/** - * 現在読み取っている要素を示すカーソルとして使うクラス - * - */ -class DecodeCursor { - private int direction;// 方向を示す 4つの方向はこの値を4で割った剰余として区別している - private int rowIndex;// 現在の行の位置 - private int columnIndex;// 現在の列の位置 - final static int RIGHT = 0; - final static int DOWN = 1; - final static int LEFT = 2; - final static int UP = 3; - - public int getDirection() { - return direction; - } - - public void setDirection(final int DIRECTION) { - this.direction = DIRECTION; - } - - public void changeDirection() { - this.direction++; - } - - public int getRowIndex() { - return rowIndex; - } - - public void setRowIndex(final int ROW_INDEX) { - this.rowIndex = ROW_INDEX; - } - - public int getColumnIndex() { - return columnIndex; - } - - public void setColumnIndex(final int COLUMN_INDEX) { - this.columnIndex = COLUMN_INDEX; - } - - // NULL(要検討)の要素に移動した際、カーソルの位置を戻す処理 - // 4つの方向はdirectionを4で割った剰余として区別する - // 0:右 1:下 2:左 3:上 - public void modifying() { - final int directionNum = this.direction % 4; - - switch (directionNum) { - case RIGHT: - this.columnIndex++; - this.rowIndex++; - break; - case DOWN: - this.columnIndex--; - this.rowIndex++; - break; - case LEFT: - this.columnIndex--; - this.rowIndex--; - break; - case UP: - this.columnIndex++; - this.rowIndex--; - break; - } - } - - // カーソルを現在進むべき方向に移動させる - // 4つの方向はdirectionを4で割った剰余として区別している - // 0:右 1:下 2:左 3:上 - public void shifting() { - final int directionNum= this.direction % 4; - - - switch (directionNum) { - case RIGHT: - this.columnIndex++; - break; - case DOWN: - this.rowIndex++; - break; - case LEFT: - this.columnIndex--; - break; - case UP: - this.rowIndex--; - break; - } - } -} diff --git a/kkanazawa/src/TwoDimensionBarcodeConversion.java b/kkanazawa/src/TwoDimensionBarcodeConversion.java new file mode 100644 index 0000000..8d85be2 --- /dev/null +++ b/kkanazawa/src/TwoDimensionBarcodeConversion.java @@ -0,0 +1,173 @@ +package paiza.src; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Scanner; +/** + * 受け取った数字を二次元の簡易バーコードに変換して出力する + * + * @author 金澤継心 + */ +public class TwoDimensionBarcodeConversion { + //入力値を一桁ごとに分ける際に使用 + final static int DIVISOR = 10; + + public static void main(final String[] args) { + + int inputNumber = inputNumber(); + + ArrayList allNumber = divideThreeEach(inputNumber); + + for (ThreeNumbers threeNum : allNumber) { + threeNum.outputDecodeResult(); + } + } + /** + * 整数値を入力して返す + * 整数の入力は以下の条件を満たす + * ・100 ≦ N ≦ 999,999,999 + * ・(N の桁数) = 3 の倍数 + */ + public static int inputNumber() { + int inputNum = 0; + + try(Scanner scanner = new Scanner(System.in)){ + inputNum = scanner.nextInt(); + }catch(Exception e) { + System.out.println("エラー発生"); + } + return inputNum; + } + /** + * 引数の整数値を1桁ごとに分け、それを三つずつまとめたリストを返す + * + * @param inputNumber 入力された整数値 + */ + public static ArrayList divideThreeEach(final int inputNumber){ + ArrayList splitNum = divideOneEach(inputNumber); + ArrayList allNumbers = new ArrayList<>(); + + //一桁ごとに分けられた数字を3つずつにまとめてリストに格納 + for (int count = 0; count < splitNum.size(); count += 2) { + ThreeNumbers three = new ThreeNumbers(); + three.setNumber(splitNum.get(count), splitNum.get(count + 1), splitNum.get(count + 2)); + allNumbers.add(three); + count++; + } + return allNumbers; + } + /** + * 引数の整数値を一桁ごとに分けてリストとして返す + * + * @param inputNumber 入力された整数値 + */ + public static ArrayList divideOneEach(final int inputNumber){ + int originNumber = inputNumber; + ArrayList splitNum = new ArrayList<>(); + while (originNumber > 0) { + splitNum.add(originNumber % DIVISOR); + originNumber /= DIVISOR; + } + Collections.reverse(splitNum); + + return splitNum; + } +} + +/** + * 入力値において並んだ三つの桁の値を保存するクラス + * + */ +class ThreeNumbers { + private int leftNumber; + private int centerNumber; + private int rightNumber; + + public int getLeftNumber() { + return leftNumber; + } + + public void setNumber(final int leftNumber, final int centerNumber, final int rightNumber) { + this.leftNumber = leftNumber; + this.centerNumber = centerNumber; + this.rightNumber = rightNumber; + } + + public void setLeftNumber(int leftNumber) { + this.leftNumber = leftNumber; + } + + public int getCenterNumber() { + return centerNumber; + } + + public void setCenterNumber(int centerNumber) { + this.centerNumber = centerNumber; + } + + public int getRightNumber() { + return rightNumber; + } + + public void setRightNumber(int rightNumber) { + this.rightNumber = rightNumber; + } + + public void outputDecodeResult() { + for(StringBuilder decodeNum : decodeThreeNum()) { + System.out.println(decodeNum); + } + } + /** + * 三つの数を二次元バーコードに変換して返す. + * decodeNum()で一つ一つの数字をバーコードに変換した後、 + * それらを横並びにつなげる + * + */ + public ArrayList decodeThreeNum() { + int left = leftNumber; + int center = centerNumber; + int right = rightNumber; + ArrayList leftDecode = decodeNum(left); + ArrayList centerDecode = decodeNum(center); + ArrayList rightDecode = decodeNum(right); + + ArrayList decodedThree = new ArrayList<>(); + //左、中央、右の数のバーコードを表す文字列で + //同じcount行目の文字列をつなげる + for (int count = 0; count < 3; count++) { + StringBuilder row = new StringBuilder(); + row.append(leftDecode.get(count)); + row.append(centerDecode.get(count)); + row.append(rightDecode.get(count)); + decodedThree.add(row); + } + return decodedThree; + } + /** + * 一つの数字を二次元バーコードに変換して返す. + * 二次元バーコードを三行の文字列として扱う. + */ + public ArrayList decodeNum(final int number) { + int num = number; + //decodedNumに1行目、2行目、3行目の文字列をそれぞれ入れる + ArrayList decodedNum = new ArrayList<>(); + + for (int count1 = 0; count1 < 3; count1++) { + //rowに1行分の文字列をを入れる + StringBuilder row = new StringBuilder(); + //1行文の文字列を作成 + for (int count2 = 0; count2 < 3; count2++) { + if (0 < num) { + row.append("#"); + } else { + row.append("."); + } + num--; + } + decodedNum.add(row); + } + return decodedNum; + } + +} -- GitLab From e33dab918063d5d944c51a770155d3f3bef8ac03 Mon Sep 17 00:00:00 2001 From: kkanazawa Date: Tue, 8 Jul 2025 16:21:03 +0900 Subject: [PATCH 5/6] =?UTF-8?q?paiza=E3=81=AE=E5=95=8F=E9=A1=8CB128?= =?UTF-8?q?=E3=81=AE=E5=9B=9E=E7=AD=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kkanazawa/src/TwoDimensionBarcodeConversion.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/kkanazawa/src/TwoDimensionBarcodeConversion.java b/kkanazawa/src/TwoDimensionBarcodeConversion.java index 8d85be2..f40db7b 100644 --- a/kkanazawa/src/TwoDimensionBarcodeConversion.java +++ b/kkanazawa/src/TwoDimensionBarcodeConversion.java @@ -14,9 +14,9 @@ public class TwoDimensionBarcodeConversion { public static void main(final String[] args) { - int inputNumber = inputNumber(); + final int inputNumber = inputNumber(); - ArrayList allNumber = divideThreeEach(inputNumber); + final ArrayList allNumber = divideThreeEach(inputNumber); for (ThreeNumbers threeNum : allNumber) { threeNum.outputDecodeResult(); @@ -44,7 +44,7 @@ public class TwoDimensionBarcodeConversion { * @param inputNumber 入力された整数値 */ public static ArrayList divideThreeEach(final int inputNumber){ - ArrayList splitNum = divideOneEach(inputNumber); + final ArrayList splitNum = divideOneEach(inputNumber); ArrayList allNumbers = new ArrayList<>(); //一桁ごとに分けられた数字を3つずつにまとめてリストに格納 @@ -125,12 +125,9 @@ class ThreeNumbers { * */ public ArrayList decodeThreeNum() { - int left = leftNumber; - int center = centerNumber; - int right = rightNumber; - ArrayList leftDecode = decodeNum(left); - ArrayList centerDecode = decodeNum(center); - ArrayList rightDecode = decodeNum(right); + ArrayList leftDecode = decodeNum(leftNumber); + ArrayList centerDecode = decodeNum(centerNumber); + ArrayList rightDecode = decodeNum(rightNumber); ArrayList decodedThree = new ArrayList<>(); //左、中央、右の数のバーコードを表す文字列で -- GitLab From 20bf65f60263573c4d54a017d2b09053b76528a6 Mon Sep 17 00:00:00 2001 From: kkanazawa Date: Tue, 8 Jul 2025 17:12:08 +0900 Subject: [PATCH 6/6] =?UTF-8?q?paiza=E3=81=AE=E5=95=8F=E9=A1=8CB128?= =?UTF-8?q?=E3=81=AE=E5=9B=9E=E7=AD=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...java => TwoDimensionBarcodeConverter.java} | 64 ++++++++----------- 1 file changed, 26 insertions(+), 38 deletions(-) rename kkanazawa/src/{TwoDimensionBarcodeConversion.java => TwoDimensionBarcodeConverter.java} (67%) diff --git a/kkanazawa/src/TwoDimensionBarcodeConversion.java b/kkanazawa/src/TwoDimensionBarcodeConverter.java similarity index 67% rename from kkanazawa/src/TwoDimensionBarcodeConversion.java rename to kkanazawa/src/TwoDimensionBarcodeConverter.java index f40db7b..43fbd51 100644 --- a/kkanazawa/src/TwoDimensionBarcodeConversion.java +++ b/kkanazawa/src/TwoDimensionBarcodeConverter.java @@ -2,13 +2,14 @@ package paiza.src; import java.util.ArrayList; import java.util.Collections; +import java.util.List; import java.util.Scanner; /** * 受け取った数字を二次元の簡易バーコードに変換して出力する * * @author 金澤継心 */ -public class TwoDimensionBarcodeConversion { +public class TwoDimensionBarcodeConverter { //入力値を一桁ごとに分ける際に使用 final static int DIVISOR = 10; @@ -16,7 +17,7 @@ public class TwoDimensionBarcodeConversion { final int inputNumber = inputNumber(); - final ArrayList allNumber = divideThreeEach(inputNumber); + final List allNumber = divideThreeEach(inputNumber); for (ThreeNumbers threeNum : allNumber) { threeNum.outputDecodeResult(); @@ -43,14 +44,13 @@ public class TwoDimensionBarcodeConversion { * * @param inputNumber 入力された整数値 */ - public static ArrayList divideThreeEach(final int inputNumber){ - final ArrayList splitNum = divideOneEach(inputNumber); - ArrayList allNumbers = new ArrayList<>(); + public static List divideThreeEach(final int inputNumber){ + final List splitNum = divideOneEach(inputNumber); + List allNumbers = new ArrayList<>(); //一桁ごとに分けられた数字を3つずつにまとめてリストに格納 for (int count = 0; count < splitNum.size(); count += 2) { - ThreeNumbers three = new ThreeNumbers(); - three.setNumber(splitNum.get(count), splitNum.get(count + 1), splitNum.get(count + 2)); + ThreeNumbers three = new ThreeNumbers(splitNum.get(count),splitNum.get(count+1),splitNum.get(count+2)); allNumbers.add(three); count++; } @@ -61,9 +61,9 @@ public class TwoDimensionBarcodeConversion { * * @param inputNumber 入力された整数値 */ - public static ArrayList divideOneEach(final int inputNumber){ + public static List divideOneEach(final int inputNumber){ int originNumber = inputNumber; - ArrayList splitNum = new ArrayList<>(); + List splitNum = new ArrayList<>(); while (originNumber > 0) { splitNum.add(originNumber % DIVISOR); originNumber /= DIVISOR; @@ -82,37 +82,25 @@ class ThreeNumbers { private int leftNumber; private int centerNumber; private int rightNumber; - - public int getLeftNumber() { - return leftNumber; - } - - public void setNumber(final int leftNumber, final int centerNumber, final int rightNumber) { + + public ThreeNumbers(int leftNumber, int centerNumber, int rightNumber) { this.leftNumber = leftNumber; this.centerNumber = centerNumber; this.rightNumber = rightNumber; } - public void setLeftNumber(int leftNumber) { - this.leftNumber = leftNumber; + public int getLeftNumber() { + return leftNumber; } public int getCenterNumber() { return centerNumber; } - public void setCenterNumber(int centerNumber) { - this.centerNumber = centerNumber; - } - public int getRightNumber() { return rightNumber; } - public void setRightNumber(int rightNumber) { - this.rightNumber = rightNumber; - } - public void outputDecodeResult() { for(StringBuilder decodeNum : decodeThreeNum()) { System.out.println(decodeNum); @@ -124,12 +112,12 @@ class ThreeNumbers { * それらを横並びにつなげる * */ - public ArrayList decodeThreeNum() { - ArrayList leftDecode = decodeNum(leftNumber); - ArrayList centerDecode = decodeNum(centerNumber); - ArrayList rightDecode = decodeNum(rightNumber); + public List decodeThreeNum() { + List leftDecode = decodeSingleNum(leftNumber); + List centerDecode = decodeSingleNum(centerNumber); + List rightDecode = decodeSingleNum(rightNumber); - ArrayList decodedThree = new ArrayList<>(); + List decodedThreeNum = new ArrayList<>(); //左、中央、右の数のバーコードを表す文字列で //同じcount行目の文字列をつなげる for (int count = 0; count < 3; count++) { @@ -137,24 +125,24 @@ class ThreeNumbers { row.append(leftDecode.get(count)); row.append(centerDecode.get(count)); row.append(rightDecode.get(count)); - decodedThree.add(row); + decodedThreeNum.add(row); } - return decodedThree; + return decodedThreeNum; } /** * 一つの数字を二次元バーコードに変換して返す. * 二次元バーコードを三行の文字列として扱う. */ - public ArrayList decodeNum(final int number) { + public List decodeSingleNum(final int number) { int num = number; //decodedNumに1行目、2行目、3行目の文字列をそれぞれ入れる - ArrayList decodedNum = new ArrayList<>(); - - for (int count1 = 0; count1 < 3; count1++) { - //rowに1行分の文字列をを入れる + List decodedNum = new ArrayList<>(); + //上から1行目、2行目、3行目の順に文字列を作成 + for (int rowindex = 0; rowindex < 3; rowindex++) { + //rowに1行分の文字列を入れる StringBuilder row = new StringBuilder(); //1行文の文字列を作成 - for (int count2 = 0; count2 < 3; count2++) { + for (int columnIndex = 0; columnIndex < 3; columnIndex++) { if (0 < num) { row.append("#"); } else { -- GitLab