From 5e750a234bb029c45e417e08ebe1fc5d78756702 Mon Sep 17 00:00:00 2001 From: rooki Date: Tue, 1 Jul 2025 16:07:03 +0900 Subject: [PATCH 1/6] =?UTF-8?q?paiza=20=E5=95=8F=E9=A1=8CC030=E3=81=AE?= =?UTF-8?q?=E5=9B=9E=E7=AD=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rooki/src/C030.java | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 rooki/src/C030.java diff --git a/rooki/src/C030.java b/rooki/src/C030.java new file mode 100644 index 0000000..f0b9b8b --- /dev/null +++ b/rooki/src/C030.java @@ -0,0 +1,42 @@ +import java.util.Scanner; + +public class C030 { + public static void main(String[] args) { + final Scanner sc = new Scanner(System.in); + + sc.nextInt(); + final int COLUMN_COUNT = sc.nextInt(); + + int binaryNumber; + int numberCount = 1; + + while (sc.hasNext()) { + int pixelValue = sc.nextInt(); + + binaryNumber = binaryConvert(pixelValue); + + formatResult(binaryNumber, numberCount, COLUMN_COUNT); + numberCount += 1; + } + + sc.close(); + } + + public static int binaryConvert(int pixelValue) { + if (pixelValue <= 127) { + pixelValue = 0; + } else { + pixelValue = 1; + } + + return pixelValue; + } + + public static void formatResult(int binaryNumber, int numberCount, int COLUMN_COUNT) { + if (numberCount % COLUMN_COUNT == 0) { + System.out.println(binaryNumber); + } else { + System.out.print(binaryNumber + " "); + } + } +} \ No newline at end of file -- GitLab From e582fee3395b071602e4c27affbd6096beb47c9d Mon Sep 17 00:00:00 2001 From: rooki Date: Wed, 2 Jul 2025 14:01:24 +0900 Subject: [PATCH 2/6] =?UTF-8?q?paiza=20=E5=95=8F=E9=A1=8CC030=E3=81=AE?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rooki/src/C030.java | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/rooki/src/C030.java b/rooki/src/C030.java index f0b9b8b..ef7ea48 100644 --- a/rooki/src/C030.java +++ b/rooki/src/C030.java @@ -1,28 +1,39 @@ import java.util.Scanner; +/** + * グレースケール画像を二値画像に変換 + * @author rooki + * @version 1.0 + */ + public class C030 { public static void main(String[] args) { final Scanner sc = new Scanner(System.in); sc.nextInt(); - final int COLUMN_COUNT = sc.nextInt(); + final int COLUMN_COUNT = sc.nextInt(); //列の数を取得 - int binaryNumber; - int numberCount = 1; + int numberCount = 1; // 何個目の数値なのか数える while (sc.hasNext()) { - int pixelValue = sc.nextInt(); + int pixelValue = sc.nextInt(); // 数値を取得 - binaryNumber = binaryConvert(pixelValue); + int binaryNumber = binaryConvert(pixelValue); //画素値を二値化 - formatResult(binaryNumber, numberCount, COLUMN_COUNT); + formatResult(binaryNumber, numberCount, COLUMN_COUNT); //列の数を整えて出力 numberCount += 1; } sc.close(); } - public static int binaryConvert(int pixelValue) { + /** + * 受け取った値を二値化して返す + * + * @param pixelValue 画素値を受け取る + * @return 二値化した数値を返す + */ + public static int binaryConvert(int pixelValue) { if (pixelValue <= 127) { pixelValue = 0; } else { @@ -32,6 +43,14 @@ public class C030 { return pixelValue; } + /** + * 取得した列の数に合わせて出力 + * + * @param binaryNumber 二値化した数値 + * @param numberCount その数値が何個目であるか + * @param COLUMN_COUNT 何列にして出力するか + * @return 二値化した数値を返す + */ public static void formatResult(int binaryNumber, int numberCount, int COLUMN_COUNT) { if (numberCount % COLUMN_COUNT == 0) { System.out.println(binaryNumber); -- GitLab From b09120329b14652857bc858a2f46fe73ceeaefa1 Mon Sep 17 00:00:00 2001 From: rooki Date: Wed, 2 Jul 2025 15:05:17 +0900 Subject: [PATCH 3/6] =?UTF-8?q?paiza=20=E5=95=8F=E9=A1=8CC030=E3=81=AE?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rooki/src/C030.java | 114 ++++++++++++++++++++++++-------------------- 1 file changed, 61 insertions(+), 53 deletions(-) diff --git a/rooki/src/C030.java b/rooki/src/C030.java index ef7ea48..6b5b1dd 100644 --- a/rooki/src/C030.java +++ b/rooki/src/C030.java @@ -1,61 +1,69 @@ import java.util.Scanner; /** - * グレースケール画像を二値画像に変換 + * グレースケール画像を二値画像に変換. + * * @author rooki * @version 1.0 */ public class C030 { - public static void main(String[] args) { - final Scanner sc = new Scanner(System.in); - - sc.nextInt(); - final int COLUMN_COUNT = sc.nextInt(); //列の数を取得 - - int numberCount = 1; // 何個目の数値なのか数える - - while (sc.hasNext()) { - int pixelValue = sc.nextInt(); // 数値を取得 - - int binaryNumber = binaryConvert(pixelValue); //画素値を二値化 - - formatResult(binaryNumber, numberCount, COLUMN_COUNT); //列の数を整えて出力 - numberCount += 1; - } - - sc.close(); - } - - /** - * 受け取った値を二値化して返す - * - * @param pixelValue 画素値を受け取る - * @return 二値化した数値を返す - */ - public static int binaryConvert(int pixelValue) { - if (pixelValue <= 127) { - pixelValue = 0; - } else { - pixelValue = 1; - } - - return pixelValue; - } - - /** - * 取得した列の数に合わせて出力 - * - * @param binaryNumber 二値化した数値 - * @param numberCount その数値が何個目であるか - * @param COLUMN_COUNT 何列にして出力するか - * @return 二値化した数値を返す - */ - public static void formatResult(int binaryNumber, int numberCount, int COLUMN_COUNT) { - if (numberCount % COLUMN_COUNT == 0) { - System.out.println(binaryNumber); - } else { - System.out.print(binaryNumber + " "); - } - } -} \ No newline at end of file + + /** + * mainメソッド. + * + * @param args 画素値を受け取る + */ + public static void main(String[] args) { + final Scanner sc = new Scanner(System.in); + + sc.nextInt(); + final int columnCount = sc.nextInt(); // 列の数を取得 + + int numberCount = 1; + + while (sc.hasNext()) { + int pixelValue = sc.nextInt(); + + int binaryNumber = binaryConvert(pixelValue); // 画素値を二値化 + + formatResult(binaryNumber, numberCount, columnCount); // 列の数を整えて出力 + numberCount += 1; // 何個目の数値かカウントアップしながら数える + } + + sc.close(); + } + + /** + * 受け取った値を二値化して返す. + * + * @param pixelValue 画素値を受け取る + * @return 二値化した数値を返す + */ + public static int binaryConvert(int pixelValue) { + if (pixelValue <= 127) { + pixelValue = 0; + } else { + pixelValue = 1; + } + + return pixelValue; + } + + /** + * 取得した列の数に合わせて出力. + * + * @param binaryNumber 二値化した数値 + * @param numberCount その数値が何個目であるか + * @param columnCount 何列にして出力するか + */ + public static void formatResult(int binaryNumber, int numberCount, int columnCount) { + if (numberCount % columnCount == 0) { + System.out.println(binaryNumber); + } else { + System.out + .print(binaryNumber + + " "); + } + } +} -- GitLab From a321b66e071344295d28410756b2e345694e47cb Mon Sep 17 00:00:00 2001 From: rooki Date: Wed, 2 Jul 2025 17:48:12 +0900 Subject: [PATCH 4/6] =?UTF-8?q?paiza=20=E5=95=8F=E9=A1=8CC030=E3=81=AE?= =?UTF-8?q?=E3=83=AC=E3=83=93=E3=83=A5=E3=83=BC=E3=81=AB=E5=AF=BE=E3=81=99?= =?UTF-8?q?=E3=82=8B=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rooki/src/C030.java | 58 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/rooki/src/C030.java b/rooki/src/C030.java index 6b5b1dd..4814cc8 100644 --- a/rooki/src/C030.java +++ b/rooki/src/C030.java @@ -4,7 +4,7 @@ import java.util.Scanner; * グレースケール画像を二値画像に変換. * * @author rooki - * @version 1.0 + * @version 2.0 */ public class C030 { @@ -12,20 +12,20 @@ public class C030 { /** * mainメソッド. * - * @param args 画素値を受け取る + * @param args 使用しない */ public static void main(String[] args) { final Scanner sc = new Scanner(System.in); - sc.nextInt(); - final int columnCount = sc.nextInt(); // 列の数を取得 + final int lineCount = scanValue(sc); // 行の数を取得 + final int columnCount = scanValue(sc); // 列の数を取得 int numberCount = 1; - while (sc.hasNext()) { - int pixelValue = sc.nextInt(); + for (int i = 0; i < lineCount * columnCount; i++) { // 行*列の回数繰り返す + final int pixelValue = scanValue(sc); - int binaryNumber = binaryConvert(pixelValue); // 画素値を二値化 + final int binaryNumber = binaryConvert(pixelValue); // 画素値を二値化 formatResult(binaryNumber, numberCount, columnCount); // 列の数を整えて出力 numberCount += 1; // 何個目の数値かカウントアップしながら数える @@ -34,20 +34,29 @@ public class C030 { sc.close(); } + /** + * 入力処理. + * + * @param sc Scannerクラス + */ + public static int scanValue(final Scanner sc) { + return sc.nextInt(); + } + /** * 受け取った値を二値化して返す. * * @param pixelValue 画素値を受け取る * @return 二値化した数値を返す */ - public static int binaryConvert(int pixelValue) { + public static int binaryConvert(final int pixelValue) { if (pixelValue <= 127) { - pixelValue = 0; - } else { - pixelValue = 1; + final Color binaryColor = Color.BLACK; + return binaryColor.getValue(); } - return pixelValue; + final Color binaryColor = Color.WHITE; + return binaryColor.getValue(); } /** @@ -66,4 +75,29 @@ public class C030 { + " "); } } + + /** + * 色の種別を持つ列挙型クラス. + * + */ + public enum Color { + + BLACK(0), + + WHITE(1); + + // フィールド + private final int value; + + // コンストラクタ + private Color(int value) { + this.value = value; + } + + // メソッド + public int getValue() { + return value; + } + + } } -- GitLab From a9ef2e8ba1d442ea793c8b8f76daf7a5edf79319 Mon Sep 17 00:00:00 2001 From: rooki Date: Thu, 3 Jul 2025 15:01:39 +0900 Subject: [PATCH 5/6] =?UTF-8?q?paiza=20=E5=95=8F=E9=A1=8CC030=E3=81=AE?= =?UTF-8?q?=E3=83=AC=E3=83=93=E3=83=A5=E3=83=BC=E3=81=AB=E5=AF=BE=E3=81=99?= =?UTF-8?q?=E3=82=8B=E4=BF=AE=E6=AD=A32?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rooki/src/C030.java | 60 +++++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/rooki/src/C030.java b/rooki/src/C030.java index 4814cc8..3de8e4d 100644 --- a/rooki/src/C030.java +++ b/rooki/src/C030.java @@ -1,3 +1,5 @@ +import java.util.ArrayList; +import java.util.List; import java.util.Scanner; /** @@ -14,33 +16,48 @@ public class C030 { * * @param args 使用しない */ - public static void main(String[] args) { - final Scanner sc = new Scanner(System.in); - - final int lineCount = scanValue(sc); // 行の数を取得 - final int columnCount = scanValue(sc); // 列の数を取得 + public static void main(final String[] args) { int numberCount = 1; - for (int i = 0; i < lineCount * columnCount; i++) { // 行*列の回数繰り返す - final int pixelValue = scanValue(sc); + final List> pixelValueList = getInputData(); - final int binaryNumber = binaryConvert(pixelValue); // 画素値を二値化 + for (int i = 0; i < pixelValueList.size(); i++) { + for (int j = 0; j < pixelValueList.get(i).size(); j++) { // 行*列の回数繰り返す + final Color binaryNumber = binaryConvert(pixelValueList.get(i).get(j)); // 画素値を二値化 - formatResult(binaryNumber, numberCount, columnCount); // 列の数を整えて出力 - numberCount += 1; // 何個目の数値かカウントアップしながら数える - } + formatResult(binaryNumber, numberCount, pixelValueList.get(i).size()); // 列の数を整えて出力 - sc.close(); + numberCount += 1; // 何個目の数値かカウントアップしながら数える + + } + } } /** * 入力処理. * - * @param sc Scannerクラス + * */ - public static int scanValue(final Scanner sc) { - return sc.nextInt(); + public static List> getInputData() { + final Scanner sc = new Scanner(System.in); + + final int lineCount = sc.nextInt(); // 行の数を取得 + final int columnCount = sc.nextInt(); // 列の数を取得 + + final List> pixelValueListOfLine = new ArrayList<>(); + + for (int line = 0; line < lineCount; line++) { + final List pixelValueListOfColumn = new ArrayList<>(); + for (int column = 0; column < columnCount; column++) { + final int pixelValue = sc.nextInt(); + pixelValueListOfColumn.add(pixelValue); + } + pixelValueListOfLine.add(pixelValueListOfColumn); + } + sc.close(); + + return pixelValueListOfLine; } /** @@ -49,14 +66,14 @@ public class C030 { * @param pixelValue 画素値を受け取る * @return 二値化した数値を返す */ - public static int binaryConvert(final int pixelValue) { + public static Color binaryConvert(final int pixelValue) { if (pixelValue <= 127) { final Color binaryColor = Color.BLACK; - return binaryColor.getValue(); + return binaryColor; } final Color binaryColor = Color.WHITE; - return binaryColor.getValue(); + return binaryColor; } /** @@ -66,12 +83,13 @@ public class C030 { * @param numberCount その数値が何個目であるか * @param columnCount 何列にして出力するか */ - public static void formatResult(int binaryNumber, int numberCount, int columnCount) { + public static void formatResult(final Color binaryNumber, + final int numberCount, final int columnCount) { if (numberCount % columnCount == 0) { - System.out.println(binaryNumber); + System.out.println(binaryNumber.getValue()); } else { System.out - .print(binaryNumber + .print(binaryNumber.getValue() + " "); } } -- GitLab From 903e5c18524d4b7f219e8c69ab4d66f1c1b39f91 Mon Sep 17 00:00:00 2001 From: rooki Date: Thu, 3 Jul 2025 17:41:54 +0900 Subject: [PATCH 6/6] =?UTF-8?q?paiza=20=E5=95=8F=E9=A1=8CC030=E3=81=AE?= =?UTF-8?q?=E3=83=AC=E3=83=93=E3=83=A5=E3=83=BC=E3=81=AB=E5=AF=BE=E3=81=99?= =?UTF-8?q?=E3=82=8B=E4=BF=AE=E6=AD=A33?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rooki/src/C030.java | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/rooki/src/C030.java b/rooki/src/C030.java index 3de8e4d..e0b0f3f 100644 --- a/rooki/src/C030.java +++ b/rooki/src/C030.java @@ -6,7 +6,7 @@ import java.util.Scanner; * グレースケール画像を二値画像に変換. * * @author rooki - * @version 2.0 + * @version 4.0 */ public class C030 { @@ -22,11 +22,12 @@ public class C030 { final List> pixelValueList = getInputData(); - for (int i = 0; i < pixelValueList.size(); i++) { - for (int j = 0; j < pixelValueList.get(i).size(); j++) { // 行*列の回数繰り返す - final Color binaryNumber = binaryConvert(pixelValueList.get(i).get(j)); // 画素値を二値化 + for (int line = 0; line < pixelValueList.size(); line++) { + for (int column = 0; column < pixelValueList.get(line).size(); column++) { // 行*列の回数繰り返す + // 画素値を二値化し、画像の色を代入する + final Color binaryColor = getColor(pixelValueList.get(line).get(column)); - formatResult(binaryNumber, numberCount, pixelValueList.get(i).size()); // 列の数を整えて出力 + outputResult(binaryColor, numberCount, column); // 列の数を整え、画像に対応した色を出力 numberCount += 1; // 何個目の数値かカウントアップしながら数える @@ -64,32 +65,29 @@ public class C030 { * 受け取った値を二値化して返す. * * @param pixelValue 画素値を受け取る - * @return 二値化した数値を返す + * @return 二値化した画像の色を返す */ - public static Color binaryConvert(final int pixelValue) { + public static Color getColor(final int pixelValue) { if (pixelValue <= 127) { - final Color binaryColor = Color.BLACK; - return binaryColor; + return Color.BLACK; } - - final Color binaryColor = Color.WHITE; - return binaryColor; + return Color.WHITE; } /** * 取得した列の数に合わせて出力. * - * @param binaryNumber 二値化した数値 - * @param numberCount その数値が何個目であるか + * @param color 与えられた画像の色 + * @param numberCount その数値が全体の何個目であるか * @param columnCount 何列にして出力するか */ - public static void formatResult(final Color binaryNumber, + public static void outputResult(final Color color, final int numberCount, final int columnCount) { if (numberCount % columnCount == 0) { - System.out.println(binaryNumber.getValue()); + System.out.println(color.getValue()); } else { System.out - .print(binaryNumber.getValue() + .print(color.getValue() + " "); } } -- GitLab