From c89b10aa37b8c677be4623ab76d3d0bfbb23afa7 Mon Sep 17 00:00:00 2001 From: kkanazawa Date: Mon, 30 Jun 2025 17:54:11 +0900 Subject: [PATCH 1/8] =?UTF-8?q?=E2=80=9Cpaiza=E3=81=AE=E5=95=8F=E9=A1=8CC0?= =?UTF-8?q?97=E3=81=AE=E5=9B=9E=E7=AD=94=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kkanazawa/src/wining_person_number.java | 40 +++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 kkanazawa/src/wining_person_number.java diff --git a/kkanazawa/src/wining_person_number.java b/kkanazawa/src/wining_person_number.java new file mode 100644 index 0000000..a62f0f0 --- /dev/null +++ b/kkanazawa/src/wining_person_number.java @@ -0,0 +1,40 @@ +package paiza_1; + +import java.util.Scanner; + +/*応募者、プレゼントAの番号、プレゼントBの番号を入力し、 + 応募者ごとにプレゼントA当選,プレゼントB当選、両方当選、当選なしのいづれかの結果を出力*/ +public class wining_person_number { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int[] numbers = new int[3]; + + // nextInt()で入力値のスペース直前の数字をnumbersに代入していく + for (int i = 0; i < numbers.length; i++) { + numbers[i] = sc.nextInt(); + } + + int applicant_number = numbers[0]; + int A_number = numbers[1]; + int B_number = numbers[2]; + + // + for (int i = 0; i < applicant_number; i++) { + int current_number = i + 1; + //応募番号を番号A、番号Bで割った剰余が0のとき、それぞれの倍数となる + boolean isAwin = (current_number % A_number == 0); + boolean isBwin = (current_number % B_number == 0); + + if (isAwin == true && isBwin == true) { + System.out.println("AB"); + } else if (isAwin == true && isBwin == false) { + System.out.println("A"); + } else if (isAwin == false && isBwin == true) { + System.out.println("B"); + } else { + System.out.println("N"); + } + } + sc.close(); + } +} \ No newline at end of file -- GitLab From d8ccc389d891bd8408cab969d4df472b66397b8e Mon Sep 17 00:00:00 2001 From: kkanazawa Date: Tue, 1 Jul 2025 14:16:00 +0900 Subject: [PATCH 2/8] =?UTF-8?q?paiza=E3=81=AE=E5=95=8F=E9=A1=8CC097?= =?UTF-8?q?=E3=81=AE=E5=9B=9E=E7=AD=94=5F=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kkanazawa/src/WiningResult.java | 62 +++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 kkanazawa/src/WiningResult.java diff --git a/kkanazawa/src/WiningResult.java b/kkanazawa/src/WiningResult.java new file mode 100644 index 0000000..70677d4 --- /dev/null +++ b/kkanazawa/src/WiningResult.java @@ -0,0 +1,62 @@ +package paiza.src; + +import java.util.Scanner; + +/** + * .応募者の人数、A賞の番号、B賞の番号から 応募者順にA賞、B賞の当選結果を出力する. + * + * + * @author 金澤継心 + */ +public class WiningResult { + + /** + * .応募者の人数、A賞の番号、B賞の番号から応募者順にA賞、B賞の当選結果を出力する. + * + * @param applicantNumber 応募者の人数 + * @param prizeAnumber この値の倍数番目の応募者がプレゼントAの当選者 + * @param prizeBnumber この値の倍数番目の応募者がプレゼントBの当選者 + */ + public static void winningResultPrint(int applicantNumber, int prizeAnumber, + int prizeBnumber) { + + for (int i = 0; i < applicantNumber; i++) { + int currentNumber = i + 1; + // 応募番号を番号A、番号Bで割った剰余が0のとき、それぞれの倍数となる + boolean isAwin = (currentNumber % prizeAnumber == 0); + boolean isBwin = (currentNumber % prizeBnumber == 0); + + //isAwin isBwinの値から応募者がどの賞に当選したか分岐 + if (isAwin == true && isBwin == true) { + System.out.println("AB"); + } else if (isAwin == true && isBwin == false) { + System.out.println("A"); + } else if (isAwin == false && isBwin == true) { + System.out.println("B"); + } else { + System.out.println("N"); + } + } + } + + /** + * .応募者の人数、A賞の番号、B賞の番号を入力し、 応募者順にA賞、B賞の当選結果を出力する. + * + */ + public static void main(final String[] args) { + Scanner sc = new Scanner(System.in); + int[] numbers = new int[3]; + + // nextInt()で入力値のスペース直前の数字をnumbersに代入していく + for (int i = 0; i < numbers.length; i++) { + numbers[i] = sc.nextInt(); + } + + int applicantNumber = numbers[0]; + int prizeAnumber = numbers[1]; + int prizeBnumber = numbers[2]; + + winningResultPrint(applicantNumber, prizeAnumber, prizeBnumber); + sc.close(); + } +} -- GitLab From 48d0e9c3e77b357393d25331fe711cba0896d5c1 Mon Sep 17 00:00:00 2001 From: kkanazawa Date: Tue, 1 Jul 2025 15:10:02 +0900 Subject: [PATCH 3/8] =?UTF-8?q?paiza=E3=81=AE=E5=95=8F=E9=A1=8CC097?= =?UTF-8?q?=E3=81=AE=E5=9B=9E=E7=AD=94=5F=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kkanazawa/src/wining_person_number.java | 40 ------------------------- 1 file changed, 40 deletions(-) delete mode 100644 kkanazawa/src/wining_person_number.java diff --git a/kkanazawa/src/wining_person_number.java b/kkanazawa/src/wining_person_number.java deleted file mode 100644 index a62f0f0..0000000 --- a/kkanazawa/src/wining_person_number.java +++ /dev/null @@ -1,40 +0,0 @@ -package paiza_1; - -import java.util.Scanner; - -/*応募者、プレゼントAの番号、プレゼントBの番号を入力し、 - 応募者ごとにプレゼントA当選,プレゼントB当選、両方当選、当選なしのいづれかの結果を出力*/ -public class wining_person_number { - public static void main(String[] args) { - Scanner sc = new Scanner(System.in); - int[] numbers = new int[3]; - - // nextInt()で入力値のスペース直前の数字をnumbersに代入していく - for (int i = 0; i < numbers.length; i++) { - numbers[i] = sc.nextInt(); - } - - int applicant_number = numbers[0]; - int A_number = numbers[1]; - int B_number = numbers[2]; - - // - for (int i = 0; i < applicant_number; i++) { - int current_number = i + 1; - //応募番号を番号A、番号Bで割った剰余が0のとき、それぞれの倍数となる - boolean isAwin = (current_number % A_number == 0); - boolean isBwin = (current_number % B_number == 0); - - if (isAwin == true && isBwin == true) { - System.out.println("AB"); - } else if (isAwin == true && isBwin == false) { - System.out.println("A"); - } else if (isAwin == false && isBwin == true) { - System.out.println("B"); - } else { - System.out.println("N"); - } - } - sc.close(); - } -} \ No newline at end of file -- GitLab From 26d2e2bc825cc2fc0975c20cf9b69c9c78b9370a Mon Sep 17 00:00:00 2001 From: kkanazawa Date: Tue, 1 Jul 2025 17:07:36 +0900 Subject: [PATCH 4/8] =?UTF-8?q?paiza=E3=81=AEC097=E3=81=AE=E5=9B=9E?= =?UTF-8?q?=E7=AD=94=EF=BC=BF=E4=BF=AE=E6=AD=A3=EF=BC=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kkanazawa/src/WinningResult.java | 70 ++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 kkanazawa/src/WinningResult.java diff --git a/kkanazawa/src/WinningResult.java b/kkanazawa/src/WinningResult.java new file mode 100644 index 0000000..2670d20 --- /dev/null +++ b/kkanazawa/src/WinningResult.java @@ -0,0 +1,70 @@ +package paiza.src; + +import java.util.Scanner; + +/** + * .応募者の人数、A賞の番号、B賞の番号から 応募者順にA賞、B賞の当選結果を出力する. + * + * @author 金澤継心 + */ +public class WinningResult { + + /** + * .応募者の人数、A賞の番号、B賞の番号を入力し、 応募者順にA賞、B賞の当選結果を出力する. + * + */ + public static void main(final String[] args) { + Scanner sc = new Scanner(System.in); + + int applicantNumber = sc.nextInt(); + int prizeAnumber = sc.nextInt(); + int prizeBnumber = sc.nextInt(); + + outputWinningResult(applicantNumber, prizeAnumber, prizeBnumber); + sc.close(); + } + + /** + * 応募者の人数、A賞の番号、B賞の番号から応募者順にA賞、B賞の当選結果を出力する. + * + * @param applicantNumber 応募者の人数 + * @param prizeAnumber この値の倍数番目の応募者がプレゼントAの当選者 + * @param prizeBnumber この値の倍数番目の応募者がプレゼントBの当選者 + */ + public static void outputWinningResult(final int applicantNumber, final int prizeAnumber, + final int prizeBnumber) { + + for (int i = 0; i < applicantNumber; i++) { + int currentNumber = i + 1; + final boolean isAwin = returnIsWinning(currentNumber, prizeAnumber); + final boolean isBwin = returnIsWinning(currentNumber, prizeBnumber); + + // isAwin isBwinの値から応募者がどの賞に当選したか分岐 + if (isAwin && isBwin) { + System.out.println("AB"); + } else if (isAwin && !isBwin) { + System.out.println("A"); + } else if (!isAwin && isBwin) { + System.out.println("B"); + } else { + System.out.println("N"); + } + } + } + + /** + * 応募者の番号と賞に割り当てられた番号から、その応募者が当選したかどうかをbool値で返す. + * + * @param currentNumber 当選判定の対象となる応募者番号 + * @param prizeNumber 賞に割り当てられた番号 + * @return 当選条件を満たす場合、trueを返す. 当選条件を満たさない場合、falseを返す + */ + public static boolean returnIsWinning(final int currentNumber, final int prizeNumber) { + // 応募者番号を賞に割り当てられた番号で割った剰余が0のとき、当選条件を満たす + if (currentNumber % prizeNumber == 0) { + return true; + } else { + return false; + } + } +} -- GitLab From 9e2ffd8026fa3e00e985cc2de3d547bff9f8ad65 Mon Sep 17 00:00:00 2001 From: kkanazawa Date: Wed, 2 Jul 2025 12:34:19 +0900 Subject: [PATCH 5/8] =?UTF-8?q?paiza=E3=81=AEC097=E3=81=AE=E5=9B=9E?= =?UTF-8?q?=E7=AD=94=EF=BC=BF=E4=BF=AE=E6=AD=A3=EF=BC=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kkanazawa/src/WinningResult.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kkanazawa/src/WinningResult.java b/kkanazawa/src/WinningResult.java index 2670d20..989b5d4 100644 --- a/kkanazawa/src/WinningResult.java +++ b/kkanazawa/src/WinningResult.java @@ -36,8 +36,8 @@ public class WinningResult { for (int i = 0; i < applicantNumber; i++) { int currentNumber = i + 1; - final boolean isAwin = returnIsWinning(currentNumber, prizeAnumber); - final boolean isBwin = returnIsWinning(currentNumber, prizeBnumber); + final boolean isAwin = isWinning(currentNumber, prizeAnumber); + final boolean isBwin = isWinning(currentNumber, prizeBnumber); // isAwin isBwinの値から応募者がどの賞に当選したか分岐 if (isAwin && isBwin) { @@ -59,7 +59,7 @@ public class WinningResult { * @param prizeNumber 賞に割り当てられた番号 * @return 当選条件を満たす場合、trueを返す. 当選条件を満たさない場合、falseを返す */ - public static boolean returnIsWinning(final int currentNumber, final int prizeNumber) { + public static boolean isWinning(final int currentNumber, final int prizeNumber) { // 応募者番号を賞に割り当てられた番号で割った剰余が0のとき、当選条件を満たす if (currentNumber % prizeNumber == 0) { return true; -- GitLab From 03aefea338b6425be973b9f25403de3b454a72bd Mon Sep 17 00:00:00 2001 From: kkanazawa Date: Wed, 2 Jul 2025 13:14:53 +0900 Subject: [PATCH 6/8] =?UTF-8?q?paiza=E3=81=AEC097=E3=81=AE=E5=9B=9E?= =?UTF-8?q?=E7=AD=94=EF=BC=BF=E4=BF=AE=E6=AD=A33?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kkanazawa/src/WinningResult2.java | 70 +++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 kkanazawa/src/WinningResult2.java diff --git a/kkanazawa/src/WinningResult2.java b/kkanazawa/src/WinningResult2.java new file mode 100644 index 0000000..f55a062 --- /dev/null +++ b/kkanazawa/src/WinningResult2.java @@ -0,0 +1,70 @@ +package paiza.src; + +import java.util.Scanner; + +/** + * .応募者の人数、A賞の番号、B賞の番号から 応募者順にA賞、B賞の当選結果を出力する. + * + * @author 金澤継心 + */ +public class WinningResult2 { + + /** + * .応募者の人数、A賞の番号、B賞の番号を入力し、 応募者順にA賞、B賞の当選結果を出力する. + * + */ + public static void main(final String[] args) { + Scanner sc = new Scanner(System.in); + + int applicantNumber = sc.nextInt(); + int prizeAnumber = sc.nextInt(); + int prizeBnumber = sc.nextInt(); + + outputWinningResult(applicantNumber, prizeAnumber, prizeBnumber); + sc.close(); + } + + /** + * 応募者の人数、A賞の番号、B賞の番号から応募者順にA賞、B賞の当選結果を出力する. + * + * @param applicantNumber 応募者の人数 + * @param prizeAnumber この値の倍数番目の応募者がプレゼントAの当選者 + * @param prizeBnumber この値の倍数番目の応募者がプレゼントBの当選者 + */ + public static void outputWinningResult(final int applicantNumber, final int prizeAnumber, + final int prizeBnumber) { + + for (int i = 0; i < applicantNumber; i++) { + int currentNumber = i + 1; + final boolean isAwin = isWinning(currentNumber, prizeAnumber); + final boolean isBwin = isWinning(currentNumber, prizeBnumber); + + // isAwin isBwinの値から応募者がどの賞に当選したか分岐 + if (isAwin && isBwin) { + System.out.println("AB"); + } else if (isAwin && !isBwin) { + System.out.println("A"); + } else if (!isAwin && isBwin) { + System.out.println("B"); + } else { + System.out.println("N"); + } + } + } + + /** + * 応募者の番号と賞に割り当てられた番号から、その応募者が当選したかどうかをbool値で返す. + * + * @param currentNumber 当選判定の対象となる応募者番号 + * @param prizeNumber 賞に割り当てられた番号 + * @return 当選条件を満たす場合、trueを返す. 当選条件を満たさない場合、falseを返す + */ + public static boolean isWinning(final int currentNumber, final int prizeNumber) { + // 応募者番号を賞に割り当てられた番号で割った剰余が0のとき、当選条件を満たす + if (currentNumber % prizeNumber == 0) { + return true; + } else { + return false; + } + } +} -- GitLab From 9741adcf100b7aab4165337e51935f9bdf894e3a Mon Sep 17 00:00:00 2001 From: kkanazawa Date: Thu, 3 Jul 2025 08:54:37 +0900 Subject: [PATCH 7/8] =?UTF-8?q?paiza=E3=81=AEC097=E3=81=AE=E5=9B=9E?= =?UTF-8?q?=E7=AD=94=EF=BC=BF=E4=BF=AE=E6=AD=A33?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kkanazawa/src/CountDonuts.java | 130 +++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 kkanazawa/src/CountDonuts.java diff --git a/kkanazawa/src/CountDonuts.java b/kkanazawa/src/CountDonuts.java new file mode 100644 index 0000000..7ba9077 --- /dev/null +++ b/kkanazawa/src/CountDonuts.java @@ -0,0 +1,130 @@ +package paiza.src; + +import java.util.Scanner; + +/** + * 二次元の入力に含まれているドーナツを検出し、その数を表示する. + * + * @author 金澤継心 + */ +public class CountDonuts { + + /** + * 入力値の行数と列数を入力した後、入力値に含まれているドーナツを検出し、その数を表示する. + * + */ + public static void main(String[] args) { + + DonutsFeature feature = new DonutsFeature(); // ドーナツを構成する要素のクラスオブジェクト + + Scanner sc = new Scanner(System.in); + int lineAmount = sc.nextInt(); // 入力値の行の数 + int columnAmount = sc.nextInt(); // 入力値の列の数 + String[] pictureRow = new String[lineAmount]; // 入力値を保存する配列 + + for (int i = 0; i < lineAmount; i++) { + pictureRow[i] = sc.next(); + } + sc.close(); + + System.out.println(returnDonutsAmount(lineAmount, columnAmount, pictureRow, feature)); + + } + + /** + * 受け取った配列に含まれているドーナツを検出し、その数を返す + * + * @param lineAmount 配列の要素数 二次元の行の数に相当 + * @param columnAmount 配列の要素一つあたりの文字数 二次元の列の数に相当 + * @param pictureRow 文字列の配列 + * @param ドーナツを構成する要素のクラスオブジェクト + */ + public static int returnDonutsAmount(final int lineAmount, final int columnAmount, + final String[] pictureRow, final DonutsFeature feature) { + + int donutsAmount = 0; // 検出したドーナツの数 + + // まず上の行から順にドーナツの構成要素1が含まれているか検索 + // ドーナツは3行必要なので、繰り返し数は(行の総数-2) + for (int i = 0; i < lineAmount - 2; i++) { + int j = 0;// これから検索する列の先頭インデックス + + // ドーナツは3列必要なので、(検索するインデックス+2)が列の総数を超えたらその行の検索終了 + while (columnAmount >= j + 2) { + // 構成要素1があるインデックスを返す + // 構成要素がなければ-1を返す + int featureIndex = pictureRow[i].indexOf(feature.getFeature1(), j); + + // ドーナツの構成要素1がヒットした場合、その下の列にも構成要素があるか調べる + if (-1 != featureIndex) { + // 1つ下の行のうち、構成要素1がヒットした列と同じ範囲の部分文字列 + String secondLine = pictureRow[i + 1].substring(featureIndex, featureIndex + 3); + // 2つ下の行のうち、構成要素1がヒットした列と同じ範囲の部分文字列 + String thirdLine = pictureRow[i + 2].substring(featureIndex, featureIndex + 3); + // 1つ下の行、2つ下の行で構成要素と合致していればドーナツを検出したとしてカウント + if (feature.isFitFeature2(secondLine) && feature.isFitFeature3(thirdLine)) { + donutsAmount++; + // 検索する列の先頭を(ドーナツを検出した列+1)に更新 + j = featureIndex + 1; + } else { + j++; // 構成要素2または構成要素3が見つからなければ検索する列の先頭を進める + } + // 構成要素1が現在の行で見つからなければ次の行の検索に移行 + } else { + break; + } + } + } + return donutsAmount; + } +} + + +/** + * ドーナツを構成する要素のクラス ドーナツの構成要素を3つの列に分けている. + * + * + */ +class DonutsFeature { + private String feature1 = "###"; // ドーナツの構成要素1列目 + private String feature2 = "#.#"; // ドーナツの構成要素2列目 + private String feature3 = "###"; // ドーナツの構成要素3列目 + + public String getFeature1() { + return feature1; + } + + public void setFeature1(final String feature1) { + this.feature1 = feature1; + } + + public String getFeature2() { + return feature2; + } + + public void setFeature2(final String feature2) { + this.feature2 = feature2; + } + + public String getFeature3() { + return feature3; + } + + public void setFeature3(final String feature3) { + this.feature3 = feature3; + } + + // 引数の文字列が構成要素と合致していればtrue, 合致していなければfalse + public boolean isFitFeature1(final String str) { + return str.equals(this.feature1); + } + + public boolean isFitFeature2(final String str) { + return str.equals(this.feature2); + } + + public boolean isFitFeature3(final String str) { + return str.equals(this.feature3); + } + +} -- GitLab From 7fac68025817a9c0bd8b3bae9954e69d2a52906a Mon Sep 17 00:00:00 2001 From: kkanazawa Date: Fri, 4 Jul 2025 17:18:46 +0900 Subject: [PATCH 8/8] =?UTF-8?q?paiza=E3=81=AE=E5=95=8F=E9=A1=8CC097?= =?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/CountDonuts.java | 130 ------------------------------ kkanazawa/src/WiningResult.java | 62 -------------- kkanazawa/src/WinningResult.java | 70 ---------------- kkanazawa/src/WinningResult2.java | 14 ++-- 4 files changed, 6 insertions(+), 270 deletions(-) delete mode 100644 kkanazawa/src/CountDonuts.java delete mode 100644 kkanazawa/src/WiningResult.java delete mode 100644 kkanazawa/src/WinningResult.java diff --git a/kkanazawa/src/CountDonuts.java b/kkanazawa/src/CountDonuts.java deleted file mode 100644 index 7ba9077..0000000 --- a/kkanazawa/src/CountDonuts.java +++ /dev/null @@ -1,130 +0,0 @@ -package paiza.src; - -import java.util.Scanner; - -/** - * 二次元の入力に含まれているドーナツを検出し、その数を表示する. - * - * @author 金澤継心 - */ -public class CountDonuts { - - /** - * 入力値の行数と列数を入力した後、入力値に含まれているドーナツを検出し、その数を表示する. - * - */ - public static void main(String[] args) { - - DonutsFeature feature = new DonutsFeature(); // ドーナツを構成する要素のクラスオブジェクト - - Scanner sc = new Scanner(System.in); - int lineAmount = sc.nextInt(); // 入力値の行の数 - int columnAmount = sc.nextInt(); // 入力値の列の数 - String[] pictureRow = new String[lineAmount]; // 入力値を保存する配列 - - for (int i = 0; i < lineAmount; i++) { - pictureRow[i] = sc.next(); - } - sc.close(); - - System.out.println(returnDonutsAmount(lineAmount, columnAmount, pictureRow, feature)); - - } - - /** - * 受け取った配列に含まれているドーナツを検出し、その数を返す - * - * @param lineAmount 配列の要素数 二次元の行の数に相当 - * @param columnAmount 配列の要素一つあたりの文字数 二次元の列の数に相当 - * @param pictureRow 文字列の配列 - * @param ドーナツを構成する要素のクラスオブジェクト - */ - public static int returnDonutsAmount(final int lineAmount, final int columnAmount, - final String[] pictureRow, final DonutsFeature feature) { - - int donutsAmount = 0; // 検出したドーナツの数 - - // まず上の行から順にドーナツの構成要素1が含まれているか検索 - // ドーナツは3行必要なので、繰り返し数は(行の総数-2) - for (int i = 0; i < lineAmount - 2; i++) { - int j = 0;// これから検索する列の先頭インデックス - - // ドーナツは3列必要なので、(検索するインデックス+2)が列の総数を超えたらその行の検索終了 - while (columnAmount >= j + 2) { - // 構成要素1があるインデックスを返す - // 構成要素がなければ-1を返す - int featureIndex = pictureRow[i].indexOf(feature.getFeature1(), j); - - // ドーナツの構成要素1がヒットした場合、その下の列にも構成要素があるか調べる - if (-1 != featureIndex) { - // 1つ下の行のうち、構成要素1がヒットした列と同じ範囲の部分文字列 - String secondLine = pictureRow[i + 1].substring(featureIndex, featureIndex + 3); - // 2つ下の行のうち、構成要素1がヒットした列と同じ範囲の部分文字列 - String thirdLine = pictureRow[i + 2].substring(featureIndex, featureIndex + 3); - // 1つ下の行、2つ下の行で構成要素と合致していればドーナツを検出したとしてカウント - if (feature.isFitFeature2(secondLine) && feature.isFitFeature3(thirdLine)) { - donutsAmount++; - // 検索する列の先頭を(ドーナツを検出した列+1)に更新 - j = featureIndex + 1; - } else { - j++; // 構成要素2または構成要素3が見つからなければ検索する列の先頭を進める - } - // 構成要素1が現在の行で見つからなければ次の行の検索に移行 - } else { - break; - } - } - } - return donutsAmount; - } -} - - -/** - * ドーナツを構成する要素のクラス ドーナツの構成要素を3つの列に分けている. - * - * - */ -class DonutsFeature { - private String feature1 = "###"; // ドーナツの構成要素1列目 - private String feature2 = "#.#"; // ドーナツの構成要素2列目 - private String feature3 = "###"; // ドーナツの構成要素3列目 - - public String getFeature1() { - return feature1; - } - - public void setFeature1(final String feature1) { - this.feature1 = feature1; - } - - public String getFeature2() { - return feature2; - } - - public void setFeature2(final String feature2) { - this.feature2 = feature2; - } - - public String getFeature3() { - return feature3; - } - - public void setFeature3(final String feature3) { - this.feature3 = feature3; - } - - // 引数の文字列が構成要素と合致していればtrue, 合致していなければfalse - public boolean isFitFeature1(final String str) { - return str.equals(this.feature1); - } - - public boolean isFitFeature2(final String str) { - return str.equals(this.feature2); - } - - public boolean isFitFeature3(final String str) { - return str.equals(this.feature3); - } - -} diff --git a/kkanazawa/src/WiningResult.java b/kkanazawa/src/WiningResult.java deleted file mode 100644 index 70677d4..0000000 --- a/kkanazawa/src/WiningResult.java +++ /dev/null @@ -1,62 +0,0 @@ -package paiza.src; - -import java.util.Scanner; - -/** - * .応募者の人数、A賞の番号、B賞の番号から 応募者順にA賞、B賞の当選結果を出力する. - * - * - * @author 金澤継心 - */ -public class WiningResult { - - /** - * .応募者の人数、A賞の番号、B賞の番号から応募者順にA賞、B賞の当選結果を出力する. - * - * @param applicantNumber 応募者の人数 - * @param prizeAnumber この値の倍数番目の応募者がプレゼントAの当選者 - * @param prizeBnumber この値の倍数番目の応募者がプレゼントBの当選者 - */ - public static void winningResultPrint(int applicantNumber, int prizeAnumber, - int prizeBnumber) { - - for (int i = 0; i < applicantNumber; i++) { - int currentNumber = i + 1; - // 応募番号を番号A、番号Bで割った剰余が0のとき、それぞれの倍数となる - boolean isAwin = (currentNumber % prizeAnumber == 0); - boolean isBwin = (currentNumber % prizeBnumber == 0); - - //isAwin isBwinの値から応募者がどの賞に当選したか分岐 - if (isAwin == true && isBwin == true) { - System.out.println("AB"); - } else if (isAwin == true && isBwin == false) { - System.out.println("A"); - } else if (isAwin == false && isBwin == true) { - System.out.println("B"); - } else { - System.out.println("N"); - } - } - } - - /** - * .応募者の人数、A賞の番号、B賞の番号を入力し、 応募者順にA賞、B賞の当選結果を出力する. - * - */ - public static void main(final String[] args) { - Scanner sc = new Scanner(System.in); - int[] numbers = new int[3]; - - // nextInt()で入力値のスペース直前の数字をnumbersに代入していく - for (int i = 0; i < numbers.length; i++) { - numbers[i] = sc.nextInt(); - } - - int applicantNumber = numbers[0]; - int prizeAnumber = numbers[1]; - int prizeBnumber = numbers[2]; - - winningResultPrint(applicantNumber, prizeAnumber, prizeBnumber); - sc.close(); - } -} diff --git a/kkanazawa/src/WinningResult.java b/kkanazawa/src/WinningResult.java deleted file mode 100644 index 989b5d4..0000000 --- a/kkanazawa/src/WinningResult.java +++ /dev/null @@ -1,70 +0,0 @@ -package paiza.src; - -import java.util.Scanner; - -/** - * .応募者の人数、A賞の番号、B賞の番号から 応募者順にA賞、B賞の当選結果を出力する. - * - * @author 金澤継心 - */ -public class WinningResult { - - /** - * .応募者の人数、A賞の番号、B賞の番号を入力し、 応募者順にA賞、B賞の当選結果を出力する. - * - */ - public static void main(final String[] args) { - Scanner sc = new Scanner(System.in); - - int applicantNumber = sc.nextInt(); - int prizeAnumber = sc.nextInt(); - int prizeBnumber = sc.nextInt(); - - outputWinningResult(applicantNumber, prizeAnumber, prizeBnumber); - sc.close(); - } - - /** - * 応募者の人数、A賞の番号、B賞の番号から応募者順にA賞、B賞の当選結果を出力する. - * - * @param applicantNumber 応募者の人数 - * @param prizeAnumber この値の倍数番目の応募者がプレゼントAの当選者 - * @param prizeBnumber この値の倍数番目の応募者がプレゼントBの当選者 - */ - public static void outputWinningResult(final int applicantNumber, final int prizeAnumber, - final int prizeBnumber) { - - for (int i = 0; i < applicantNumber; i++) { - int currentNumber = i + 1; - final boolean isAwin = isWinning(currentNumber, prizeAnumber); - final boolean isBwin = isWinning(currentNumber, prizeBnumber); - - // isAwin isBwinの値から応募者がどの賞に当選したか分岐 - if (isAwin && isBwin) { - System.out.println("AB"); - } else if (isAwin && !isBwin) { - System.out.println("A"); - } else if (!isAwin && isBwin) { - System.out.println("B"); - } else { - System.out.println("N"); - } - } - } - - /** - * 応募者の番号と賞に割り当てられた番号から、その応募者が当選したかどうかをbool値で返す. - * - * @param currentNumber 当選判定の対象となる応募者番号 - * @param prizeNumber 賞に割り当てられた番号 - * @return 当選条件を満たす場合、trueを返す. 当選条件を満たさない場合、falseを返す - */ - public static boolean isWinning(final int currentNumber, final int prizeNumber) { - // 応募者番号を賞に割り当てられた番号で割った剰余が0のとき、当選条件を満たす - if (currentNumber % prizeNumber == 0) { - return true; - } else { - return false; - } - } -} diff --git a/kkanazawa/src/WinningResult2.java b/kkanazawa/src/WinningResult2.java index f55a062..2a770e5 100644 --- a/kkanazawa/src/WinningResult2.java +++ b/kkanazawa/src/WinningResult2.java @@ -16,12 +16,12 @@ public class WinningResult2 { public static void main(final String[] args) { Scanner sc = new Scanner(System.in); - int applicantNumber = sc.nextInt(); - int prizeAnumber = sc.nextInt(); - int prizeBnumber = sc.nextInt(); + final int applicantNumber = sc.nextInt(); + final int prizeAnumber = sc.nextInt(); + final int prizeBnumber = sc.nextInt(); + sc.close(); outputWinningResult(applicantNumber, prizeAnumber, prizeBnumber); - sc.close(); } /** @@ -34,8 +34,7 @@ public class WinningResult2 { public static void outputWinningResult(final int applicantNumber, final int prizeAnumber, final int prizeBnumber) { - for (int i = 0; i < applicantNumber; i++) { - int currentNumber = i + 1; + for (int currentNumber = 1; currentNumber <= applicantNumber; currentNumber++) { final boolean isAwin = isWinning(currentNumber, prizeAnumber); final boolean isBwin = isWinning(currentNumber, prizeBnumber); @@ -63,8 +62,7 @@ public class WinningResult2 { // 応募者番号を賞に割り当てられた番号で割った剰余が0のとき、当選条件を満たす if (currentNumber % prizeNumber == 0) { return true; - } else { - return false; } + return false; } } -- GitLab