From 1aee25876ea237b60f6084e0a75e804107572674 Mon Sep 17 00:00:00 2001 From: ryouji Date: Mon, 30 Jun 2025 16:46:51 +0900 Subject: [PATCH 01/19] =?UTF-8?q?paiza=E3=81=AEC144:=E3=81=98=E3=82=83?= =?UTF-8?q?=E3=82=93=E3=81=91=E3=82=93=E3=81=AE=E7=B5=90=E6=9E=9C=E5=95=8F?= =?UTF-8?q?=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rsuzuki/README.md | 2 + rsuzuki/src/.gitkeep | 0 rsuzuki/src/C069_Festival.java | 82 +++++++++++++++++++++++++++++ rsuzuki/src/win.java | 28 ++++++++++ rsuzuki/test/.gitkeep | 0 rsuzuki/test/C069_FestivalTest.java | 26 +++++++++ 6 files changed, 138 insertions(+) create mode 100644 rsuzuki/README.md create mode 100644 rsuzuki/src/.gitkeep create mode 100644 rsuzuki/src/C069_Festival.java create mode 100644 rsuzuki/src/win.java create mode 100644 rsuzuki/test/.gitkeep create mode 100644 rsuzuki/test/C069_FestivalTest.java diff --git a/rsuzuki/README.md b/rsuzuki/README.md new file mode 100644 index 0000000..796c95d --- /dev/null +++ b/rsuzuki/README.md @@ -0,0 +1,2 @@ +# Paiza +knoda用 diff --git a/rsuzuki/src/.gitkeep b/rsuzuki/src/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/rsuzuki/src/C069_Festival.java b/rsuzuki/src/C069_Festival.java new file mode 100644 index 0000000..b64383c --- /dev/null +++ b/rsuzuki/src/C069_Festival.java @@ -0,0 +1,82 @@ +package hellojunit; + +import java.util.Scanner; + +public class C069_Festival { + + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + final int year = scan.nextInt(); + final int month = scan.nextInt(); + final int day = scan.nextInt(); + final int festivalMonth = scan.nextInt(); + final int festivalDay = scan.nextInt(); + + Festival festival = new Festival(year, month, day, festivalMonth, festivalDay); + System.out.println(festival.getDayUntilFestival()); + + scan.close(); + } +} + + +class Festival { + private int year; + private int month; + private int day; + private final int festivalMonth; + private final int festivalDay; + private static final int ODD_NUMBER_MONTH_DAY = 13; // 奇数月の日数 + private static final int EVEN_NUMBER_MONTH_DAY = 15; // 偶数月の日数 + + public Festival(final int year, final int month, final int day, final int festivalMonth, final int festivalDay) { + this.year = year; + this.month = month; + this.day = day; + this.festivalMonth = festivalMonth; + this.festivalDay = festivalDay; + } + + // ある月の日数を取得するメソッド + private int getDaysOfMonth(final int month) { + if (month % 2 == 0) { + return EVEN_NUMBER_MONTH_DAY; + } + return ODD_NUMBER_MONTH_DAY; + } + + // 祭りが開催される年であるかを判定するメソッド + private boolean isFestivalYear(final int year) { + return year % 4 == 1; + } + + // 年と月をカウントアップするメソッド + private void countUpMonth() { + month++; + if (month > 13) { + month = 1; + year++; + } + } + + // 祭り開催までの残り日数を取得するメソッド + public int getDayUntilFestival() { + int tempYear = year + 1; + int dayUntilFestival = 0; + while (!isFestivalYear(tempYear)) { + tempYear++; + } + + final int festivalYear = tempYear; + + dayUntilFestival += getDaysOfMonth(month) - day; + countUpMonth(); + + while ((year != festivalYear) || (month != festivalMonth)) { + dayUntilFestival += getDaysOfMonth(month); + countUpMonth(); + } + dayUntilFestival += festivalDay; + return dayUntilFestival; + } +} diff --git a/rsuzuki/src/win.java b/rsuzuki/src/win.java new file mode 100644 index 0000000..2de39e0 --- /dev/null +++ b/rsuzuki/src/win.java @@ -0,0 +1,28 @@ +package paiza_c; + +import java.util.Scanner; + +public class win { + + public static void main(String[] args) { + // 自分の得意な言語で + // Let's チャレンジ!! + Scanner sc = new Scanner(System.in); + int N = sc.nextInt(); + String line = sc.nextLine(); + int count = 0; + for (int i = 0; i < N; i++) { + String A_N = sc.next(); + String B_N = sc.next(); + if(A_N.equals("G") && B_N.equals("C")) { + count += 1; + }else if (A_N.equals("P") && B_N.equals("G")) { + count += 1; + }else if (A_N.equals("C") && B_N.equals("P")) { + count += 1; + } + } + System.out.println(count); + } + +} diff --git a/rsuzuki/test/.gitkeep b/rsuzuki/test/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/rsuzuki/test/C069_FestivalTest.java b/rsuzuki/test/C069_FestivalTest.java new file mode 100644 index 0000000..cf883eb --- /dev/null +++ b/rsuzuki/test/C069_FestivalTest.java @@ -0,0 +1,26 @@ +package hellojunit; + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; + +import org.junit.Test; + +public class C069_FestivalTest { + + @Test + public void 日数を取得するテスト1() { + Festival sut = new Festival(2000, 12, 10, 1, 10); + int expected = 28; + int actual = sut.getDayUntilFestival(); + assertThat(actual, is(expected)); + } + + @Test + public void 日数を取得するテスト2() { + Festival sut = new Festival(1994, 4, 8, 7, 13); + int expected = 591; + int actual = sut.getDayUntilFestival(); + assertThat(actual, is(expected)); + } + +} -- GitLab From 869bd443ea427cf5076cd72be5a4a21ea0387ca1 Mon Sep 17 00:00:00 2001 From: ryouji Date: Tue, 1 Jul 2025 11:36:31 +0900 Subject: [PATCH 02/19] =?UTF-8?q?C144=20=E3=81=98=E3=82=83=E3=82=93?= =?UTF-8?q?=E3=81=91=E3=82=93=E3=81=AE=E7=B5=90=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rsuzuki/src/.gitkeep | 0 rsuzuki/src/C069_Festival.java | 82 ------------------------- rsuzuki/src/{win.java => C144_win.java} | 3 +- rsuzuki/test/.gitkeep | 0 rsuzuki/test/C069_FestivalTest.java | 26 -------- 5 files changed, 2 insertions(+), 109 deletions(-) delete mode 100644 rsuzuki/src/.gitkeep delete mode 100644 rsuzuki/src/C069_Festival.java rename rsuzuki/src/{win.java => C144_win.java} (96%) delete mode 100644 rsuzuki/test/.gitkeep delete mode 100644 rsuzuki/test/C069_FestivalTest.java diff --git a/rsuzuki/src/.gitkeep b/rsuzuki/src/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/rsuzuki/src/C069_Festival.java b/rsuzuki/src/C069_Festival.java deleted file mode 100644 index b64383c..0000000 --- a/rsuzuki/src/C069_Festival.java +++ /dev/null @@ -1,82 +0,0 @@ -package hellojunit; - -import java.util.Scanner; - -public class C069_Festival { - - public static void main(String[] args) { - Scanner scan = new Scanner(System.in); - final int year = scan.nextInt(); - final int month = scan.nextInt(); - final int day = scan.nextInt(); - final int festivalMonth = scan.nextInt(); - final int festivalDay = scan.nextInt(); - - Festival festival = new Festival(year, month, day, festivalMonth, festivalDay); - System.out.println(festival.getDayUntilFestival()); - - scan.close(); - } -} - - -class Festival { - private int year; - private int month; - private int day; - private final int festivalMonth; - private final int festivalDay; - private static final int ODD_NUMBER_MONTH_DAY = 13; // 奇数月の日数 - private static final int EVEN_NUMBER_MONTH_DAY = 15; // 偶数月の日数 - - public Festival(final int year, final int month, final int day, final int festivalMonth, final int festivalDay) { - this.year = year; - this.month = month; - this.day = day; - this.festivalMonth = festivalMonth; - this.festivalDay = festivalDay; - } - - // ある月の日数を取得するメソッド - private int getDaysOfMonth(final int month) { - if (month % 2 == 0) { - return EVEN_NUMBER_MONTH_DAY; - } - return ODD_NUMBER_MONTH_DAY; - } - - // 祭りが開催される年であるかを判定するメソッド - private boolean isFestivalYear(final int year) { - return year % 4 == 1; - } - - // 年と月をカウントアップするメソッド - private void countUpMonth() { - month++; - if (month > 13) { - month = 1; - year++; - } - } - - // 祭り開催までの残り日数を取得するメソッド - public int getDayUntilFestival() { - int tempYear = year + 1; - int dayUntilFestival = 0; - while (!isFestivalYear(tempYear)) { - tempYear++; - } - - final int festivalYear = tempYear; - - dayUntilFestival += getDaysOfMonth(month) - day; - countUpMonth(); - - while ((year != festivalYear) || (month != festivalMonth)) { - dayUntilFestival += getDaysOfMonth(month); - countUpMonth(); - } - dayUntilFestival += festivalDay; - return dayUntilFestival; - } -} diff --git a/rsuzuki/src/win.java b/rsuzuki/src/C144_win.java similarity index 96% rename from rsuzuki/src/win.java rename to rsuzuki/src/C144_win.java index 2de39e0..315c4de 100644 --- a/rsuzuki/src/win.java +++ b/rsuzuki/src/C144_win.java @@ -2,7 +2,7 @@ package paiza_c; import java.util.Scanner; -public class win { +public class C144_win { public static void main(String[] args) { // 自分の得意な言語で @@ -25,4 +25,5 @@ public class win { System.out.println(count); } + } diff --git a/rsuzuki/test/.gitkeep b/rsuzuki/test/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/rsuzuki/test/C069_FestivalTest.java b/rsuzuki/test/C069_FestivalTest.java deleted file mode 100644 index cf883eb..0000000 --- a/rsuzuki/test/C069_FestivalTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package hellojunit; - -import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; - -import org.junit.Test; - -public class C069_FestivalTest { - - @Test - public void 日数を取得するテスト1() { - Festival sut = new Festival(2000, 12, 10, 1, 10); - int expected = 28; - int actual = sut.getDayUntilFestival(); - assertThat(actual, is(expected)); - } - - @Test - public void 日数を取得するテスト2() { - Festival sut = new Festival(1994, 4, 8, 7, 13); - int expected = 591; - int actual = sut.getDayUntilFestival(); - assertThat(actual, is(expected)); - } - -} -- GitLab From a4af80ddb3df7dad15c06237f9fd54042fdcafcc Mon Sep 17 00:00:00 2001 From: ryouji Date: Tue, 1 Jul 2025 17:08:52 +0900 Subject: [PATCH 03/19] =?UTF-8?q?paiza=E3=81=AE=E5=95=8F=E9=A1=8CC144=20?= =?UTF-8?q?=E3=81=98=E3=82=83=E3=82=93=E3=81=91=E3=82=93=E3=81=AE=E7=B5=90?= =?UTF-8?q?=E6=9E=9C=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rsuzuki/src/C144_win.java | 109 +++++++++++++++++++++++++++++++------- 1 file changed, 89 insertions(+), 20 deletions(-) diff --git a/rsuzuki/src/C144_win.java b/rsuzuki/src/C144_win.java index 315c4de..01397b6 100644 --- a/rsuzuki/src/C144_win.java +++ b/rsuzuki/src/C144_win.java @@ -2,28 +2,97 @@ package paiza_c; import java.util.Scanner; +enum RockPaperScissorsType { + Rock("G"), Paper("P"), Scissors("C"); + + private final String caption; + + private RockPaperScissorsType(final String caption) { + this.caption = caption; + } + + public static RockPaperScissorsType fromCaption(final String string) { + for (final RockPaperScissorsType type : values()) { + if (type.caption.equals(string)) { + return type; + } + } + return null; + } +} + +// 入力を受け取るクラス +final class Input { + private final Scanner scanner; + + public Input(final Scanner scanner) { + this.scanner = scanner; + } + + public int readGameCount() { + final int count = scanner.nextInt(); + scanner.nextLine(); + return count; + } + + public RockPaperScissorsType readHand() { + return RockPaperScissorsType.fromCaption(scanner.next()); + } +} + +// じゃんけんのロジックのクラス +final class Logic { + + public boolean Win(final RockPaperScissorsType handA, final RockPaperScissorsType handB) { + if (handA == RockPaperScissorsType.Rock && handB == RockPaperScissorsType.Scissors) { + return true; + } else if (handA == RockPaperScissorsType.Paper && handB == RockPaperScissorsType.Rock) { + return true; + } else if (handA == RockPaperScissorsType.Scissors && handB == RockPaperScissorsType.Paper) { + return true; + } + return false; + } +} + +// 結果に集計するクラス +final class Result { + private int winCount; + + public Result() { + this.winCount = 0; + } + + // 勝利数をインクリメントする + public void incrementresult() { + this.winCount++; + } + + // 現在の勝利数を取得する + public int getresult() { + return winCount; + } +} + public class C144_win { + public static void main(String[] args) { + final Scanner sc = new Scanner(System.in); + final Input input = new Input(sc); + final Logic logic = new Logic(); + final Result result = new Result(); + + final int N = input.readGameCount(); + + for (int i = 0; i < N; i++) { + final RockPaperScissorsType playerAHand = input.readHand(); + final RockPaperScissorsType playerBHand = input.readHand(); - public static void main(String[] args) { - // 自分の得意な言語で - // Let's チャレンジ!! - Scanner sc = new Scanner(System.in); - int N = sc.nextInt(); - String line = sc.nextLine(); - int count = 0; - for (int i = 0; i < N; i++) { - String A_N = sc.next(); - String B_N = sc.next(); - if(A_N.equals("G") && B_N.equals("C")) { - count += 1; - }else if (A_N.equals("P") && B_N.equals("G")) { - count += 1; - }else if (A_N.equals("C") && B_N.equals("P")) { - count += 1; - } - } - System.out.println(count); - } + if (logic.Win(playerAHand, playerBHand)) { + result.incrementresult(); + } + } + System.out.println(result.getresult()); + } } -- GitLab From 30354c4a78207f77fce2a907ba55f3feab970ceb Mon Sep 17 00:00:00 2001 From: ryouji Date: Wed, 2 Jul 2025 11:44:09 +0900 Subject: [PATCH 04/19] =?UTF-8?q?paiza=E3=81=AEC158:=E8=8A=B1=E3=81=AE?= =?UTF-8?q?=E3=83=96=E3=83=BC=E3=82=B1=E5=95=8F=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rsuzuki/src/C144_win.java | 98 ------------------------------------ rsuzuki/src/C157_flower.java | 46 +++++++++++++++++ 2 files changed, 46 insertions(+), 98 deletions(-) delete mode 100644 rsuzuki/src/C144_win.java create mode 100644 rsuzuki/src/C157_flower.java diff --git a/rsuzuki/src/C144_win.java b/rsuzuki/src/C144_win.java deleted file mode 100644 index 01397b6..0000000 --- a/rsuzuki/src/C144_win.java +++ /dev/null @@ -1,98 +0,0 @@ -package paiza_c; - -import java.util.Scanner; - -enum RockPaperScissorsType { - Rock("G"), Paper("P"), Scissors("C"); - - private final String caption; - - private RockPaperScissorsType(final String caption) { - this.caption = caption; - } - - public static RockPaperScissorsType fromCaption(final String string) { - for (final RockPaperScissorsType type : values()) { - if (type.caption.equals(string)) { - return type; - } - } - return null; - } -} - -// 入力を受け取るクラス -final class Input { - private final Scanner scanner; - - public Input(final Scanner scanner) { - this.scanner = scanner; - } - - public int readGameCount() { - final int count = scanner.nextInt(); - scanner.nextLine(); - return count; - } - - public RockPaperScissorsType readHand() { - return RockPaperScissorsType.fromCaption(scanner.next()); - } -} - -// じゃんけんのロジックのクラス -final class Logic { - - public boolean Win(final RockPaperScissorsType handA, final RockPaperScissorsType handB) { - if (handA == RockPaperScissorsType.Rock && handB == RockPaperScissorsType.Scissors) { - return true; - } else if (handA == RockPaperScissorsType.Paper && handB == RockPaperScissorsType.Rock) { - return true; - } else if (handA == RockPaperScissorsType.Scissors && handB == RockPaperScissorsType.Paper) { - return true; - } - return false; - } -} - -// 結果に集計するクラス -final class Result { - private int winCount; - - public Result() { - this.winCount = 0; - } - - // 勝利数をインクリメントする - public void incrementresult() { - this.winCount++; - } - - // 現在の勝利数を取得する - public int getresult() { - return winCount; - } -} - -public class C144_win { - public static void main(String[] args) { - final Scanner sc = new Scanner(System.in); - final Input input = new Input(sc); - final Logic logic = new Logic(); - final Result result = new Result(); - - final int N = input.readGameCount(); - - for (int i = 0; i < N; i++) { - final RockPaperScissorsType playerAHand = input.readHand(); - final RockPaperScissorsType playerBHand = input.readHand(); - - if (logic.Win(playerAHand, playerBHand)) { - result.incrementresult(); - } - } - - System.out.println(result.getresult()); - - } -} diff --git a/rsuzuki/src/C157_flower.java b/rsuzuki/src/C157_flower.java new file mode 100644 index 0000000..62482fa --- /dev/null +++ b/rsuzuki/src/C157_flower.java @@ -0,0 +1,46 @@ +package paiza_c; + +import java.util.ArrayList; +import java.util.Scanner; + +/** 入力を受け取るクラス */ +final class Input { + private final Scanner scanner; + + public Input(final Scanner scanner) { + this.scanner = scanner; + } + + public int readGameCount() { + final int count = scanner.nextInt(); + scanner.nextLine(); + return count; + } + + public RockPaperScissorsType readHand() { + return RockPaperScissorsType.fromCaption(scanner.next()); + } +} + +public class C157_flower { + public static void main(String[] args) { + final Scanner sc = new Scanner(System.in); + final Input input = new Input(sc); + + final int N = input.readGameCount(); + + ArrayList flowers = new ArrayList<>(); + /** 花を格納する配列 */ + + for (int i = 0; i < N; i++) { + String a_i = sc.next(); + + if (!flowers.contains(a_i)) { + flowers.add(a_i); + } + } + + System.out.println(flowers.size()); + } + +} -- GitLab From a7557f9c7cffcd76323275e62aa99e5d8f805aa4 Mon Sep 17 00:00:00 2001 From: ryouji Date: Wed, 2 Jul 2025 14:17:30 +0900 Subject: [PATCH 05/19] =?UTF-8?q?paiza=E3=81=AEC158:=E8=8A=B1=E3=81=AE?= =?UTF-8?q?=E3=83=96=E3=83=BC=E3=82=B1=E5=95=8F=E9=A1=8Cwo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rsuzuki/src/C157_flower.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/rsuzuki/src/C157_flower.java b/rsuzuki/src/C157_flower.java index 62482fa..c390b3b 100644 --- a/rsuzuki/src/C157_flower.java +++ b/rsuzuki/src/C157_flower.java @@ -4,30 +4,26 @@ import java.util.ArrayList; import java.util.Scanner; /** 入力を受け取るクラス */ -final class Input { +final class FlowerInput { private final Scanner scanner; - public Input(final Scanner scanner) { + public FlowerInput(final Scanner scanner) { this.scanner = scanner; } - public int readGameCount() { + public int readFlowerCount() { final int count = scanner.nextInt(); scanner.nextLine(); return count; } - - public RockPaperScissorsType readHand() { - return RockPaperScissorsType.fromCaption(scanner.next()); - } } public class C157_flower { public static void main(String[] args) { final Scanner sc = new Scanner(System.in); - final Input input = new Input(sc); + final FlowerInput input = new FlowerInput(sc); - final int N = input.readGameCount(); + final int N = input.readFlowerCount(); ArrayList flowers = new ArrayList<>(); /** 花を格納する配列 */ -- GitLab From 3765802e02026129cc3f183048a861e94ad2e5be Mon Sep 17 00:00:00 2001 From: ryouji Date: Wed, 2 Jul 2025 17:27:38 +0900 Subject: [PATCH 06/19] =?UTF-8?q?paiza=E3=81=AEC158:=E8=8A=B1=E3=81=AE?= =?UTF-8?q?=E3=83=96=E3=83=BC=E3=82=B1=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rsuzuki/src/C157_flower.java | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/rsuzuki/src/C157_flower.java b/rsuzuki/src/C157_flower.java index c390b3b..28420f1 100644 --- a/rsuzuki/src/C157_flower.java +++ b/rsuzuki/src/C157_flower.java @@ -1,6 +1,7 @@ package paiza_c; import java.util.ArrayList; +import java.util.List; import java.util.Scanner; /** 入力を受け取るクラス */ @@ -20,23 +21,27 @@ final class FlowerInput { public class C157_flower { public static void main(String[] args) { - final Scanner sc = new Scanner(System.in); - final FlowerInput input = new FlowerInput(sc); + try (final Scanner sc = new Scanner(System.in)) { - final int N = input.readFlowerCount(); + final FlowerInput input = new FlowerInput(sc); - ArrayList flowers = new ArrayList<>(); - /** 花を格納する配列 */ + /** すべての花の本数 */ + final int Flower_count = input.readFlowerCount(); - for (int i = 0; i < N; i++) { - String a_i = sc.next(); + /** 花を格納する配列 */ + List flowers = new ArrayList<>(); - if (!flowers.contains(a_i)) { - flowers.add(a_i); + for (int i = 0; i < Flower_count; i++) { + /** 花の種類 */ + String flower_type = sc.next(); + + if (!flowers.contains(flower_type)) { + flowers.add(flower_type); + } } - } - System.out.println(flowers.size()); + System.out.println(flowers.size()); + } } } -- GitLab From d0b622944b780afd6a92f3dc99edc1740acc58d4 Mon Sep 17 00:00:00 2001 From: ryouji Date: Thu, 3 Jul 2025 09:04:52 +0900 Subject: [PATCH 07/19] =?UTF-8?q?paiza=E3=81=AEC158:=E8=8A=B1=E3=81=AE?= =?UTF-8?q?=E3=83=96=E3=83=BC=E3=82=B1=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A32?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rsuzuki/src/C157_flower.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/rsuzuki/src/C157_flower.java b/rsuzuki/src/C157_flower.java index 28420f1..319f859 100644 --- a/rsuzuki/src/C157_flower.java +++ b/rsuzuki/src/C157_flower.java @@ -5,10 +5,10 @@ import java.util.List; import java.util.Scanner; /** 入力を受け取るクラス */ -final class FlowerInput { +final class flowerInput { private final Scanner scanner; - public FlowerInput(final Scanner scanner) { + public flowerInput(final Scanner scanner) { this.scanner = scanner; } @@ -23,20 +23,20 @@ public class C157_flower { public static void main(String[] args) { try (final Scanner sc = new Scanner(System.in)) { - final FlowerInput input = new FlowerInput(sc); + final flowerInput input = new flowerInput(sc); /** すべての花の本数 */ - final int Flower_count = input.readFlowerCount(); + final int flowerCount = input.readFlowerCount(); /** 花を格納する配列 */ List flowers = new ArrayList<>(); - for (int i = 0; i < Flower_count; i++) { + for (int i = 0; i < flowerCount; i++) { /** 花の種類 */ - String flower_type = sc.next(); + String flowerType = sc.next(); - if (!flowers.contains(flower_type)) { - flowers.add(flower_type); + if (!flowers.contains(flowerType)) { + flowers.add(flowerType); } } -- GitLab From 48e9aee44669209bb17a24858bebab593a8ad470 Mon Sep 17 00:00:00 2001 From: ryouji Date: Thu, 3 Jul 2025 13:07:28 +0900 Subject: [PATCH 08/19] =?UTF-8?q?paiza=E3=81=AEC014:=E3=83=9C=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E3=81=8C=E5=85=A5=E3=82=8B=E7=AE=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rsuzuki/src/C014_ball.java | 99 ++++++++++++++++++++++++++++++++++++ rsuzuki/src/C157_flower.java | 47 ----------------- 2 files changed, 99 insertions(+), 47 deletions(-) create mode 100644 rsuzuki/src/C014_ball.java delete mode 100644 rsuzuki/src/C157_flower.java diff --git a/rsuzuki/src/C014_ball.java b/rsuzuki/src/C014_ball.java new file mode 100644 index 0000000..ea7f169 --- /dev/null +++ b/rsuzuki/src/C014_ball.java @@ -0,0 +1,99 @@ +package paiza_c; + +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +/** 入力を受け取るクラス */ +final class BoxInput { + private final int number; + /** 箱の数 */ + private final int radius; + /** ボール半径 */ + private final int[][] boxDimensions; + + /** [箱のインデックス][高さ、幅、奥行き] */ + + public BoxInput() { + Scanner scanner = new Scanner(System.in); + this.number = scanner.nextInt(); + this.radius = scanner.nextInt(); + + this.boxDimensions = new int[number][3]; + /** 箱の大きさを格納する配列 */ + + for (int i = 0; i < number; i++) { + this.boxDimensions[i][0] = scanner.nextInt(); // 高さ + this.boxDimensions[i][1] = scanner.nextInt(); // 幅 + this.boxDimensions[i][2] = scanner.nextInt(); // 奥行き + } + } + + public int getNumber() { + return number; + } + + public int getradius() { + return radius; + } + + public int[][] getBoxDimensions() { + return boxDimensions; + } +} + +/** ロジック */ +final class BallLogic { + private int ballDimensions; + /** ボールの直径 */ + private List fitBoxnumber; + + /** ボールが入る箱を格納する配列 */ + + public BallLogic(int radius) { + this.ballDimensions = 2 * radius; + this.fitBoxnumber = new ArrayList<>(); + } + + /** 辺の中で一番小さい値とボールの直径を比較 */ + public void comparison(int number, int h, int w, int d) { + int min = Math.min(h, Math.min(w, d)); + + if (min >= ballDimensions) { + fitBoxnumber.add(number); + } + } + + /** 出力 */ + public void printNumber() { + for (int i = 0; i < fitBoxnumber.size(); i++) { + System.out.println(fitBoxnumber.get(i)); + } + } +} + +public class C014_ball { + + public static void main(String[] args) { + BoxInput input = new BoxInput(); + + final int number = input.getNumber(); + final int radius = input.getradius(); + final int[][] boxDimensions = input.getBoxDimensions(); + + final BallLogic logic = new BallLogic(radius); + + for (int i = 0; i < number; i++) { + int boxnumber = i + 1; + int h = boxDimensions[i][0]; + int w = boxDimensions[i][1]; + int d = boxDimensions[i][2]; + + logic.comparison(boxnumber, h, w, d); + } + + logic.printNumber(); + + } + +} diff --git a/rsuzuki/src/C157_flower.java b/rsuzuki/src/C157_flower.java deleted file mode 100644 index 319f859..0000000 --- a/rsuzuki/src/C157_flower.java +++ /dev/null @@ -1,47 +0,0 @@ -package paiza_c; - -import java.util.ArrayList; -import java.util.List; -import java.util.Scanner; - -/** 入力を受け取るクラス */ -final class flowerInput { - private final Scanner scanner; - - public flowerInput(final Scanner scanner) { - this.scanner = scanner; - } - - public int readFlowerCount() { - final int count = scanner.nextInt(); - scanner.nextLine(); - return count; - } -} - -public class C157_flower { - public static void main(String[] args) { - try (final Scanner sc = new Scanner(System.in)) { - - final flowerInput input = new flowerInput(sc); - - /** すべての花の本数 */ - final int flowerCount = input.readFlowerCount(); - - /** 花を格納する配列 */ - List flowers = new ArrayList<>(); - - for (int i = 0; i < flowerCount; i++) { - /** 花の種類 */ - String flowerType = sc.next(); - - if (!flowers.contains(flowerType)) { - flowers.add(flowerType); - } - } - - System.out.println(flowers.size()); - } - } - -} -- GitLab From e8247a0d3a8bae3d18942d915c7dd38f0262f679 Mon Sep 17 00:00:00 2001 From: ryouji Date: Thu, 3 Jul 2025 15:22:55 +0900 Subject: [PATCH 09/19] =?UTF-8?q?paiza=E3=81=AEC021:=E6=9A=B4=E9=A2=A8?= =?UTF-8?q?=E5=9F=9F=E3=81=AE=E4=B8=AD=E3=81=AB=E3=81=84=E3=81=BE=E3=81=99?= =?UTF-8?q?=E3=81=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rsuzuki/src/C014_ball.java | 99 ----------------------------- rsuzuki/src/C021_storm.java | 120 ++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+), 99 deletions(-) delete mode 100644 rsuzuki/src/C014_ball.java create mode 100644 rsuzuki/src/C021_storm.java diff --git a/rsuzuki/src/C014_ball.java b/rsuzuki/src/C014_ball.java deleted file mode 100644 index ea7f169..0000000 --- a/rsuzuki/src/C014_ball.java +++ /dev/null @@ -1,99 +0,0 @@ -package paiza_c; - -import java.util.ArrayList; -import java.util.List; -import java.util.Scanner; - -/** 入力を受け取るクラス */ -final class BoxInput { - private final int number; - /** 箱の数 */ - private final int radius; - /** ボール半径 */ - private final int[][] boxDimensions; - - /** [箱のインデックス][高さ、幅、奥行き] */ - - public BoxInput() { - Scanner scanner = new Scanner(System.in); - this.number = scanner.nextInt(); - this.radius = scanner.nextInt(); - - this.boxDimensions = new int[number][3]; - /** 箱の大きさを格納する配列 */ - - for (int i = 0; i < number; i++) { - this.boxDimensions[i][0] = scanner.nextInt(); // 高さ - this.boxDimensions[i][1] = scanner.nextInt(); // 幅 - this.boxDimensions[i][2] = scanner.nextInt(); // 奥行き - } - } - - public int getNumber() { - return number; - } - - public int getradius() { - return radius; - } - - public int[][] getBoxDimensions() { - return boxDimensions; - } -} - -/** ロジック */ -final class BallLogic { - private int ballDimensions; - /** ボールの直径 */ - private List fitBoxnumber; - - /** ボールが入る箱を格納する配列 */ - - public BallLogic(int radius) { - this.ballDimensions = 2 * radius; - this.fitBoxnumber = new ArrayList<>(); - } - - /** 辺の中で一番小さい値とボールの直径を比較 */ - public void comparison(int number, int h, int w, int d) { - int min = Math.min(h, Math.min(w, d)); - - if (min >= ballDimensions) { - fitBoxnumber.add(number); - } - } - - /** 出力 */ - public void printNumber() { - for (int i = 0; i < fitBoxnumber.size(); i++) { - System.out.println(fitBoxnumber.get(i)); - } - } -} - -public class C014_ball { - - public static void main(String[] args) { - BoxInput input = new BoxInput(); - - final int number = input.getNumber(); - final int radius = input.getradius(); - final int[][] boxDimensions = input.getBoxDimensions(); - - final BallLogic logic = new BallLogic(radius); - - for (int i = 0; i < number; i++) { - int boxnumber = i + 1; - int h = boxDimensions[i][0]; - int w = boxDimensions[i][1]; - int d = boxDimensions[i][2]; - - logic.comparison(boxnumber, h, w, d); - } - - logic.printNumber(); - - } - -} diff --git a/rsuzuki/src/C021_storm.java b/rsuzuki/src/C021_storm.java new file mode 100644 index 0000000..333f292 --- /dev/null +++ b/rsuzuki/src/C021_storm.java @@ -0,0 +1,120 @@ +package paiza_c; + +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +/** 入力を受け取るクラス */ +final class stormInput { + /** 円の中心座標(xc,yc) */ + private final int xc; + private final int yc; + /** 半径 */ + private final int r_1; + private final int r_2; + /** 人の数 */ + private final int N; + + /** 複数のx座標,y座標を格納する */ + private final List x_N; + private final List y_N; + + public stormInput() { + Scanner scanner = new Scanner(System.in); + + this.xc = scanner.nextInt(); + this.yc = scanner.nextInt(); + this.r_1 = scanner.nextInt(); + this.r_2 = scanner.nextInt(); + this.N = scanner.nextInt(); + this.x_N = new ArrayList<>(); + this.y_N = new ArrayList<>(); + + /** N番目の人の座標を格納 */ + for (int i = 0; i < N; i++) { + this.x_N.add(scanner.nextInt()); + this.y_N.add(scanner.nextInt()); + } + } + + public int getXC() { + return xc; + } + + public int getYC() { + return yc; + } + + public int getR_1() { + return r_1; + } + + public int getR_2() { + return r_2; + } + + public int getN() { + return N; + } + + public List getX_N() { + return x_N; + } + + public List getY_N() { + return y_N; + } + +} + +/** ロジック */ +final class stormLogic { + /** 暴風域の中心から人物までの距離の2乗 */ + private int distanceStorm; + /** 半径の2乗 */ + private int radius_1; + private int radius_2; + + public stormLogic(int xc, int yc, int r_1, int r_2, int X_N, int Y_N) { + this.distanceStorm = (X_N - xc) * (X_N - xc) + (Y_N - yc) * (Y_N - yc); + this.radius_1 = r_1 * r_1; + this.radius_2 = r_2 * r_2; + } + + /** 台風の暴風域にいるかどうか */ + public boolean range() { + if (radius_1 <= distanceStorm && distanceStorm <= radius_2) { + return true; + } + return false; + } + +} + +public class C021_storm { + public static void main(String[] args) { + stormInput input = new stormInput(); + + final int xc = input.getXC(); + final int yc = input.getYC(); + final int r_1 = input.getR_1(); + final int r_2 = input.getR_2(); + final int N = input.getN(); + final List x_N = input.getX_N(); + final List y_N = input.getY_N(); + + for (int i = 0; i < N; i++) { + int X_N = x_N.get(i); + int Y_N = y_N.get(i); + + stormLogic logic = new stormLogic(xc, yc, r_1, r_2, X_N, Y_N); + + if (logic.range()) { + System.out.println("yes"); + } else { + System.out.println("no"); + } + } + + } +} -- GitLab From 39499f00978645f67dbc96c697b5a8245f847701 Mon Sep 17 00:00:00 2001 From: ryouji Date: Thu, 3 Jul 2025 15:24:19 +0900 Subject: [PATCH 10/19] =?UTF-8?q?paiza=E3=81=AEC014:=E3=83=9C=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E3=81=8C=E5=85=A5=E3=82=8B=E7=AE=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rsuzuki/src/C014_ball.java | 99 +++++++++++++++++++++++++++++ rsuzuki/src/C021_storm.java | 120 ------------------------------------ 2 files changed, 99 insertions(+), 120 deletions(-) create mode 100644 rsuzuki/src/C014_ball.java delete mode 100644 rsuzuki/src/C021_storm.java diff --git a/rsuzuki/src/C014_ball.java b/rsuzuki/src/C014_ball.java new file mode 100644 index 0000000..ea7f169 --- /dev/null +++ b/rsuzuki/src/C014_ball.java @@ -0,0 +1,99 @@ +package paiza_c; + +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +/** 入力を受け取るクラス */ +final class BoxInput { + private final int number; + /** 箱の数 */ + private final int radius; + /** ボール半径 */ + private final int[][] boxDimensions; + + /** [箱のインデックス][高さ、幅、奥行き] */ + + public BoxInput() { + Scanner scanner = new Scanner(System.in); + this.number = scanner.nextInt(); + this.radius = scanner.nextInt(); + + this.boxDimensions = new int[number][3]; + /** 箱の大きさを格納する配列 */ + + for (int i = 0; i < number; i++) { + this.boxDimensions[i][0] = scanner.nextInt(); // 高さ + this.boxDimensions[i][1] = scanner.nextInt(); // 幅 + this.boxDimensions[i][2] = scanner.nextInt(); // 奥行き + } + } + + public int getNumber() { + return number; + } + + public int getradius() { + return radius; + } + + public int[][] getBoxDimensions() { + return boxDimensions; + } +} + +/** ロジック */ +final class BallLogic { + private int ballDimensions; + /** ボールの直径 */ + private List fitBoxnumber; + + /** ボールが入る箱を格納する配列 */ + + public BallLogic(int radius) { + this.ballDimensions = 2 * radius; + this.fitBoxnumber = new ArrayList<>(); + } + + /** 辺の中で一番小さい値とボールの直径を比較 */ + public void comparison(int number, int h, int w, int d) { + int min = Math.min(h, Math.min(w, d)); + + if (min >= ballDimensions) { + fitBoxnumber.add(number); + } + } + + /** 出力 */ + public void printNumber() { + for (int i = 0; i < fitBoxnumber.size(); i++) { + System.out.println(fitBoxnumber.get(i)); + } + } +} + +public class C014_ball { + + public static void main(String[] args) { + BoxInput input = new BoxInput(); + + final int number = input.getNumber(); + final int radius = input.getradius(); + final int[][] boxDimensions = input.getBoxDimensions(); + + final BallLogic logic = new BallLogic(radius); + + for (int i = 0; i < number; i++) { + int boxnumber = i + 1; + int h = boxDimensions[i][0]; + int w = boxDimensions[i][1]; + int d = boxDimensions[i][2]; + + logic.comparison(boxnumber, h, w, d); + } + + logic.printNumber(); + + } + +} diff --git a/rsuzuki/src/C021_storm.java b/rsuzuki/src/C021_storm.java deleted file mode 100644 index 333f292..0000000 --- a/rsuzuki/src/C021_storm.java +++ /dev/null @@ -1,120 +0,0 @@ -package paiza_c; - -import java.util.ArrayList; -import java.util.List; -import java.util.Scanner; - -/** 入力を受け取るクラス */ -final class stormInput { - /** 円の中心座標(xc,yc) */ - private final int xc; - private final int yc; - /** 半径 */ - private final int r_1; - private final int r_2; - /** 人の数 */ - private final int N; - - /** 複数のx座標,y座標を格納する */ - private final List x_N; - private final List y_N; - - public stormInput() { - Scanner scanner = new Scanner(System.in); - - this.xc = scanner.nextInt(); - this.yc = scanner.nextInt(); - this.r_1 = scanner.nextInt(); - this.r_2 = scanner.nextInt(); - this.N = scanner.nextInt(); - this.x_N = new ArrayList<>(); - this.y_N = new ArrayList<>(); - - /** N番目の人の座標を格納 */ - for (int i = 0; i < N; i++) { - this.x_N.add(scanner.nextInt()); - this.y_N.add(scanner.nextInt()); - } - } - - public int getXC() { - return xc; - } - - public int getYC() { - return yc; - } - - public int getR_1() { - return r_1; - } - - public int getR_2() { - return r_2; - } - - public int getN() { - return N; - } - - public List getX_N() { - return x_N; - } - - public List getY_N() { - return y_N; - } - -} - -/** ロジック */ -final class stormLogic { - /** 暴風域の中心から人物までの距離の2乗 */ - private int distanceStorm; - /** 半径の2乗 */ - private int radius_1; - private int radius_2; - - public stormLogic(int xc, int yc, int r_1, int r_2, int X_N, int Y_N) { - this.distanceStorm = (X_N - xc) * (X_N - xc) + (Y_N - yc) * (Y_N - yc); - this.radius_1 = r_1 * r_1; - this.radius_2 = r_2 * r_2; - } - - /** 台風の暴風域にいるかどうか */ - public boolean range() { - if (radius_1 <= distanceStorm && distanceStorm <= radius_2) { - return true; - } - return false; - } - -} - -public class C021_storm { - public static void main(String[] args) { - stormInput input = new stormInput(); - - final int xc = input.getXC(); - final int yc = input.getYC(); - final int r_1 = input.getR_1(); - final int r_2 = input.getR_2(); - final int N = input.getN(); - final List x_N = input.getX_N(); - final List y_N = input.getY_N(); - - for (int i = 0; i < N; i++) { - int X_N = x_N.get(i); - int Y_N = y_N.get(i); - - stormLogic logic = new stormLogic(xc, yc, r_1, r_2, X_N, Y_N); - - if (logic.range()) { - System.out.println("yes"); - } else { - System.out.println("no"); - } - } - - } -} -- GitLab From 31cf35e7a8738bd5625d174e0a400736a3c8674c Mon Sep 17 00:00:00 2001 From: ryouji Date: Thu, 3 Jul 2025 17:50:31 +0900 Subject: [PATCH 11/19] =?UTF-8?q?paiza=E3=81=AEC014:=E3=83=9C=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E3=81=8C=E5=85=A5=E3=82=8B=E7=AE=B1=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rsuzuki/src/C014_ball.java | 76 +++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/rsuzuki/src/C014_ball.java b/rsuzuki/src/C014_ball.java index ea7f169..1da654b 100644 --- a/rsuzuki/src/C014_ball.java +++ b/rsuzuki/src/C014_ball.java @@ -4,37 +4,27 @@ import java.util.ArrayList; import java.util.List; import java.util.Scanner; -/** 入力を受け取るクラス */ -final class BoxInput { - private final int number; +/** 箱とボールのデータを保持するクラス */ +final class BoxData { /** 箱の数 */ - private final int radius; + private final int boxNumber; /** ボール半径 */ - private final int[][] boxDimensions; - + private final int ballRadius; /** [箱のインデックス][高さ、幅、奥行き] */ + private final int[][] boxDimensions; - public BoxInput() { - Scanner scanner = new Scanner(System.in); - this.number = scanner.nextInt(); - this.radius = scanner.nextInt(); - - this.boxDimensions = new int[number][3]; - /** 箱の大きさを格納する配列 */ - - for (int i = 0; i < number; i++) { - this.boxDimensions[i][0] = scanner.nextInt(); // 高さ - this.boxDimensions[i][1] = scanner.nextInt(); // 幅 - this.boxDimensions[i][2] = scanner.nextInt(); // 奥行き - } + public BoxData(int boxNumber, int ballRadius, int[][] boxDimensions) { + this.boxNumber = boxNumber; + this.ballRadius = ballRadius; + this.boxDimensions = boxDimensions; } - public int getNumber() { - return number; + public int getBoxNumber() { + return boxNumber; } - public int getradius() { - return radius; + public int getBallRadius() { + return ballRadius; } public int[][] getBoxDimensions() { @@ -44,11 +34,10 @@ final class BoxInput { /** ロジック */ final class BallLogic { - private int ballDimensions; /** ボールの直径 */ - private List fitBoxnumber; - + private int ballDimensions; /** ボールが入る箱を格納する配列 */ + private List fitBoxnumber; public BallLogic(int radius) { this.ballDimensions = 2 * radius; @@ -56,8 +45,8 @@ final class BallLogic { } /** 辺の中で一番小さい値とボールの直径を比較 */ - public void comparison(int number, int h, int w, int d) { - int min = Math.min(h, Math.min(w, d)); + public void compare(int number, int height, int width, int depth) { + int min = Math.min(height, Math.min(width, depth)); if (min >= ballDimensions) { fitBoxnumber.add(number); @@ -75,21 +64,32 @@ final class BallLogic { public class C014_ball { public static void main(String[] args) { - BoxInput input = new BoxInput(); + Scanner scanner = new Scanner(System.in); + + int boxNumber = scanner.nextInt(); + int ballRadius = scanner.nextInt(); + + int[][] boxDimensions = new int[boxNumber][3]; + + for (int i = 0; i < boxNumber; i++) { + boxDimensions[i][0] = scanner.nextInt(); // 高さ + boxDimensions[i][1] = scanner.nextInt(); // 幅 + boxDimensions[i][2] = scanner.nextInt(); // 奥行き + } + scanner.close(); - final int number = input.getNumber(); - final int radius = input.getradius(); - final int[][] boxDimensions = input.getBoxDimensions(); + /** データを保持するクラスにセット */ + BoxData boxData = new BoxData(boxNumber, ballRadius, boxDimensions); - final BallLogic logic = new BallLogic(radius); + final BallLogic logic = new BallLogic(ballRadius); - for (int i = 0; i < number; i++) { + for (int i = 0; i < boxData.getBoxNumber(); i++) { int boxnumber = i + 1; - int h = boxDimensions[i][0]; - int w = boxDimensions[i][1]; - int d = boxDimensions[i][2]; + int height = boxDimensions[i][0]; + int width = boxDimensions[i][1]; + int depth = boxDimensions[i][2]; - logic.comparison(boxnumber, h, w, d); + logic.compare(boxnumber, height, width, depth); } logic.printNumber(); -- GitLab From defaf25f074e8590a24e25303901086eef6dd2a9 Mon Sep 17 00:00:00 2001 From: ryouji Date: Fri, 4 Jul 2025 10:49:06 +0900 Subject: [PATCH 12/19] =?UTF-8?q?paiza=E3=81=AEC021:=E6=9A=B4=E9=A2=A8?= =?UTF-8?q?=E5=9F=9F=E3=81=AB=E3=81=84=E3=81=BE=E3=81=99=E3=81=8B=EF=BC=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rsuzuki/src/C014_ball.java | 99 ---------------------------- rsuzuki/src/C021_storm.java | 125 ++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+), 99 deletions(-) delete mode 100644 rsuzuki/src/C014_ball.java create mode 100644 rsuzuki/src/C021_storm.java diff --git a/rsuzuki/src/C014_ball.java b/rsuzuki/src/C014_ball.java deleted file mode 100644 index 1da654b..0000000 --- a/rsuzuki/src/C014_ball.java +++ /dev/null @@ -1,99 +0,0 @@ -package paiza_c; - -import java.util.ArrayList; -import java.util.List; -import java.util.Scanner; - -/** 箱とボールのデータを保持するクラス */ -final class BoxData { - /** 箱の数 */ - private final int boxNumber; - /** ボール半径 */ - private final int ballRadius; - /** [箱のインデックス][高さ、幅、奥行き] */ - private final int[][] boxDimensions; - - public BoxData(int boxNumber, int ballRadius, int[][] boxDimensions) { - this.boxNumber = boxNumber; - this.ballRadius = ballRadius; - this.boxDimensions = boxDimensions; - } - - public int getBoxNumber() { - return boxNumber; - } - - public int getBallRadius() { - return ballRadius; - } - - public int[][] getBoxDimensions() { - return boxDimensions; - } -} - -/** ロジック */ -final class BallLogic { - /** ボールの直径 */ - private int ballDimensions; - /** ボールが入る箱を格納する配列 */ - private List fitBoxnumber; - - public BallLogic(int radius) { - this.ballDimensions = 2 * radius; - this.fitBoxnumber = new ArrayList<>(); - } - - /** 辺の中で一番小さい値とボールの直径を比較 */ - public void compare(int number, int height, int width, int depth) { - int min = Math.min(height, Math.min(width, depth)); - - if (min >= ballDimensions) { - fitBoxnumber.add(number); - } - } - - /** 出力 */ - public void printNumber() { - for (int i = 0; i < fitBoxnumber.size(); i++) { - System.out.println(fitBoxnumber.get(i)); - } - } -} - -public class C014_ball { - - public static void main(String[] args) { - Scanner scanner = new Scanner(System.in); - - int boxNumber = scanner.nextInt(); - int ballRadius = scanner.nextInt(); - - int[][] boxDimensions = new int[boxNumber][3]; - - for (int i = 0; i < boxNumber; i++) { - boxDimensions[i][0] = scanner.nextInt(); // 高さ - boxDimensions[i][1] = scanner.nextInt(); // 幅 - boxDimensions[i][2] = scanner.nextInt(); // 奥行き - } - scanner.close(); - - /** データを保持するクラスにセット */ - BoxData boxData = new BoxData(boxNumber, ballRadius, boxDimensions); - - final BallLogic logic = new BallLogic(ballRadius); - - for (int i = 0; i < boxData.getBoxNumber(); i++) { - int boxnumber = i + 1; - int height = boxDimensions[i][0]; - int width = boxDimensions[i][1]; - int depth = boxDimensions[i][2]; - - logic.compare(boxnumber, height, width, depth); - } - - logic.printNumber(); - - } - -} diff --git a/rsuzuki/src/C021_storm.java b/rsuzuki/src/C021_storm.java new file mode 100644 index 0000000..6013337 --- /dev/null +++ b/rsuzuki/src/C021_storm.java @@ -0,0 +1,125 @@ +package paiza_c; + +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +/** データを保持するクラス */ +final class stormData { + /** 円の中心座標(xc,yc) */ + private final int xc; + private final int yc; + /** 半径 */ + private final int r_1; + private final int r_2; + /** 人の数 */ + private final int N; + + /** 複数のx座標,y座標を格納する */ + private final List x_N; + private final List y_N; + + public stormData(int xc, int yc, int r_1, int r_2, int N, List x_N, List y_N) { + this.xc = xc; + this.yc = yc; + this.r_1 = r_1; + this.r_2 = r_2; + this.N = N; + this.x_N = x_N; + this.y_N = y_N; + } + + public int getXC() { + return xc; + } + + public int getYC() { + return yc; + } + + public int getR_1() { + return r_1; + } + + public int getR_2() { + return r_2; + } + + public int getN() { + return N; + } + + public List getX_N() { + return x_N; + } + + public List getY_N() { + return y_N; + } + +} + +/** ロジック */ +final class stormLogic { + /** 暴風域の中心から人物までの距離の2乗 */ + private int distanceStorm; + /** 半径の2乗 */ + private int radius_1; + private int radius_2; + + public stormLogic(int xc, int yc, int r_1, int r_2, int X_N, int Y_N) { + this.distanceStorm = (X_N - xc) * (X_N - xc) + (Y_N - yc) * (Y_N - yc); + this.radius_1 = r_1 * r_1; + this.radius_2 = r_2 * r_2; + } + + /** 台風の暴風域にいるかどうか */ + public boolean range() { + if (radius_1 <= distanceStorm && distanceStorm <= radius_2) { + return true; + } + return false; + } + +} + +public class C021_storm { + public static void main(String[] args) { + /** 入力された値を取得 */ + Scanner scanner = new Scanner(System.in); + + int xc = scanner.nextInt(); + int yc = scanner.nextInt(); + int r_1 = scanner.nextInt(); + int r_2 = scanner.nextInt(); + int N = scanner.nextInt(); + List x_N = new ArrayList<>(); + List y_N = new ArrayList<>(); + + /** N番目の人の座標を格納 */ + for (int i = 0; i < N; i++) { + x_N.add(scanner.nextInt()); + y_N.add(scanner.nextInt()); + } + scanner.close(); + + stormData input = new stormData(xc, yc, r_1, r_2, N, x_N, y_N); + + final List x_N_fromdata = input.getX_N(); + final List y_N_fromdata = input.getY_N(); + + for (int i = 0; i < N; i++) { + int X_N = x_N_fromdata.get(i); + int Y_N = y_N_fromdata.get(i); + + stormLogic logic = new stormLogic(xc, yc, r_1, r_2, X_N, Y_N); + + if (logic.range()) { + System.out.println("yes"); + } else { + System.out.println("no"); + } + } + + } +} -- GitLab From 534f9ea8083d8d884de8351fdb5b229268d77a24 Mon Sep 17 00:00:00 2001 From: ryouji Date: Fri, 4 Jul 2025 17:10:37 +0900 Subject: [PATCH 13/19] =?UTF-8?q?paiza=E3=81=AEC021:=E6=9A=B4=E9=A2=A8?= =?UTF-8?q?=E5=9F=9F=E3=81=AB=E3=81=84=E3=81=BE=E3=81=99=E3=81=8B=EF=BC=9F?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rsuzuki/src/C021_storm.java | 167 ++++++++++++++---------------------- 1 file changed, 66 insertions(+), 101 deletions(-) diff --git a/rsuzuki/src/C021_storm.java b/rsuzuki/src/C021_storm.java index 6013337..c309b79 100644 --- a/rsuzuki/src/C021_storm.java +++ b/rsuzuki/src/C021_storm.java @@ -1,125 +1,90 @@ package paiza_c; -import java.util.ArrayList; -import java.util.List; import java.util.Scanner; -/** データを保持するクラス */ -final class stormData { - /** 円の中心座標(xc,yc) */ - private final int xc; - private final int yc; - /** 半径 */ - private final int r_1; - private final int r_2; - /** 人の数 */ - private final int N; - - /** 複数のx座標,y座標を格納する */ - private final List x_N; - private final List y_N; - - public stormData(int xc, int yc, int r_1, int r_2, int N, List x_N, List y_N) { - this.xc = xc; - this.yc = yc; - this.r_1 = r_1; - this.r_2 = r_2; - this.N = N; - this.x_N = x_N; - this.y_N = y_N; - } - - public int getXC() { - return xc; - } - - public int getYC() { - return yc; - } - - public int getR_1() { - return r_1; - } - - public int getR_2() { - return r_2; - } - - public int getN() { - return N; - } - - public List getX_N() { - return x_N; - } - - public List getY_N() { - return y_N; - } - -} - -/** ロジック */ -final class stormLogic { - /** 暴風域の中心から人物までの距離の2乗 */ - private int distanceStorm; - /** 半径の2乗 */ - private int radius_1; - private int radius_2; - - public stormLogic(int xc, int yc, int r_1, int r_2, int X_N, int Y_N) { - this.distanceStorm = (X_N - xc) * (X_N - xc) + (Y_N - yc) * (Y_N - yc); - this.radius_1 = r_1 * r_1; - this.radius_2 = r_2 * r_2; +/** + * 台風の情報を保持し、暴風域判定ロジックを提供するクラス + */ +class Typhoon { + /** 台風の中心X座標 */ + private final int centerX; + /** 台風の中心Y座標 */ + private final int centerY; + /** 内円の半径の2乗 */ + private final int inRadiusSq; + /** 外円の半径の2乗 */ + private final int outRadiusSq; + + /** + * @param centerX 台風の中心X座標 + * @param centerY 台風の中心Y座標 + * @param innerRadius 内円の半径 + * @param outerRadius 外円の半径 + */ + public Typhoon(int centerX, int centerY, int inRadius, int outRadius) { + this.centerX = centerX; + this.centerY = centerY; + this.inRadiusSq = inRadius * inRadius; + this.outRadiusSq = outRadius * outRadius; } - /** 台風の暴風域にいるかどうか */ - public boolean range() { - if (radius_1 <= distanceStorm && distanceStorm <= radius_2) { - return true; - } - return false; + /** + * 指定された座標がこの台風の暴風域内にあるかどうかを判定 + * + * @param pointX 判定対象のX座標 + * @param pointY 判定対象のY座標 + * @return 座標が暴風域内にある場合はtrue、そうでない場合はfalse + */ + public boolean isInStormRange(int pointX, int pointY) { + // 台風の中心から指定された地点までの距離の2乗を計算 + int distanceStormSq = (pointX - centerX) * (pointX - centerX) + (pointY - centerY) * (pointY - centerY); + // 距離の2乗が内円の半径の2乗以上、かつ外円の半径の2乗以下であれば暴風域内 + return inRadiusSq <= distanceStormSq && distanceStormSq <= outRadiusSq; } - } public class C021_storm { public static void main(String[] args) { - /** 入力された値を取得 */ Scanner scanner = new Scanner(System.in); - int xc = scanner.nextInt(); - int yc = scanner.nextInt(); - int r_1 = scanner.nextInt(); - int r_2 = scanner.nextInt(); - int N = scanner.nextInt(); - List x_N = new ArrayList<>(); - List y_N = new ArrayList<>(); + Typhoon currentTyphoon = readTyphoonData(scanner); + int numberOfPeople = scanner.nextInt(); + PeopleStormCheck(scanner, currentTyphoon, numberOfPeople); - /** N番目の人の座標を格納 */ - for (int i = 0; i < N; i++) { - x_N.add(scanner.nextInt()); - y_N.add(scanner.nextInt()); - } scanner.close(); + } - stormData input = new stormData(xc, yc, r_1, r_2, N, x_N, y_N); - - final List x_N_fromdata = input.getX_N(); - final List y_N_fromdata = input.getY_N(); - - for (int i = 0; i < N; i++) { - int X_N = x_N_fromdata.get(i); - int Y_N = y_N_fromdata.get(i); - - stormLogic logic = new stormLogic(xc, yc, r_1, r_2, X_N, Y_N); + /** + * 標準入力から台風の中心座標と半径を読み込み、Typhoonオブジェクトを生成して返す + * + * @param scanner 標準入力からの読み込みに使用するScannerオブジェクト + * @return 読み込んだデータに基づいて生成されたTyphoonオブジェクト + */ + private static Typhoon readTyphoonData(Scanner scanner) { + final int xc = scanner.nextInt(); + final int yc = scanner.nextInt(); + final int r_1 = scanner.nextInt(); + final int r_2 = scanner.nextInt(); + return new Typhoon(xc, yc, r_1, r_2); + } - if (logic.range()) { + /** + * 標準入力から指定された人数の座標を読み込み、 それぞれの座標が与えられた台風の暴風域内にあるかを判定し、結果を標準出力に出す + * + * @param scanner 標準入力からの読み込みに使用するScannerオブジェクト + * @param typhoon 判定に使用するTyphoonオブジェクト + * @param numberOfPeople 判定する人の数 + */ + private static void PeopleStormCheck(Scanner scanner, Typhoon typhoon, int numberOfPeople) { + for (int i = 0; i < numberOfPeople; i++) { + final int personX = scanner.nextInt(); + final int personY = scanner.nextInt(); + + if (typhoon.isInStormRange(personX, personY)) { System.out.println("yes"); } else { System.out.println("no"); } } - } } -- GitLab From caf7efd126ff23157ac5f15813055bc8d979b032 Mon Sep 17 00:00:00 2001 From: ryouji Date: Mon, 7 Jul 2025 13:16:35 +0900 Subject: [PATCH 14/19] =?UTF-8?q?paiza=E3=81=AEB136:=E3=83=81=E3=83=A7?= =?UTF-8?q?=E3=82=B3=E3=81=AE=E3=81=8A=E8=BF=94=E3=81=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rsuzuki/src/B136_chocolate.java | 190 ++++++++++++++++++++++++++++++++ rsuzuki/src/C021_storm.java | 90 --------------- 2 files changed, 190 insertions(+), 90 deletions(-) create mode 100644 rsuzuki/src/B136_chocolate.java delete mode 100644 rsuzuki/src/C021_storm.java diff --git a/rsuzuki/src/B136_chocolate.java b/rsuzuki/src/B136_chocolate.java new file mode 100644 index 0000000..df80074 --- /dev/null +++ b/rsuzuki/src/B136_chocolate.java @@ -0,0 +1,190 @@ +package paiza_c; + +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +/** データを保持するクラス */ +final class ChocoData { + /** 移動回数 */ + private final int movingTime; + /** 縦の席数 */ + private final int ySeat; + /** 横の席数 */ + private final int xSeat; + /** 自分の座席がどこか */ + private int yPlayer; + private int xPlayer; + /** 移動経路FBLR */ + private final String movingCommand; + /** 座席でもらえるチョコの数を格納する配列 */ + final int[][] chocoNumber; + + /** + * ChocoDataの新しいインスタンスを生成 + * + * @param movingTime 移動回数 + * @param ySeat 縦の席数 + * @param xSeat 横の席数 + * @param yPlayer プレイヤーの初期縦位置 + * @param xPlayer プレイヤーの初期横位置 + * @param movingCommand 移動コマンド文字列 + * @param chocoNumber 各座席のチョコの数を格納する二次元配列 + */ + public ChocoData(int movingTime, int ySeat, int xSeat, int yPlayer, int xPlayer, String movingCommand, + int[][] chocoNumber) { + this.movingTime = movingTime; + this.ySeat = ySeat; + this.xSeat = xSeat; + this.yPlayer = yPlayer; + this.xPlayer = xPlayer; + this.movingCommand = movingCommand; + this.chocoNumber = chocoNumber; + } + + public int getMovingTime() { + return movingTime; + } + + public int getYSear() { + return ySeat; + } + + public int getXSeat() { + return xSeat; + } + + public int getYPlayer() { + return yPlayer; + } + + public int getXPlayer() { + return xPlayer; + } + + public String getMovingCommand() { + return movingCommand; + } + + public int getChocoNumber(int y, int x) { + return chocoNumber[y][x]; + } + + public void setSy(int sy) { + this.yPlayer = sy; + } + + public void setSx(int sx) { + this.xPlayer = sx; + } +} + +/** + * ロジック + */ +final class ChocoLogic { + private final ChocoData data; + /** 集計用リスト */ + private final List chocoValues; + + public ChocoLogic(ChocoData data) { + this.data = data; + this.chocoValues = new ArrayList<>(); + } + + /** + * 移動コマンドに基づいてプレイヤーを移動させ、通過した座席のチョコの数を集計 + */ + public void Commands() { + for (int i = 0; i < data.getMovingTime(); i++) { + char command = data.getMovingCommand().charAt(i); + movePlayer(command); + chocoValues.add(data.getChocoNumber(data.getYPlayer(), data.getXPlayer())); + } + } + + /** + * 指定されたコマンドに基づいてプレイヤーを移動 + */ + private void movePlayer(char command) { + int yPlayer = data.getYPlayer(); + int xPlayer = data.getXPlayer(); + int ySeat = data.getYSear(); + int xSeat = data.getXSeat(); + + if (command == 'F') { // 前進 (上) + if (yPlayer > 0) { + data.setSy(yPlayer - 1); + } + } else if (command == 'B') { // 後退 (下) + if (yPlayer < ySeat - 1) { + data.setSy(yPlayer + 1); + } + } else if (command == 'L') { // 左 + if (xPlayer > 0) { + data.setSx(xPlayer - 1); + } + } else if (command == 'R') { // 右 + if (xPlayer < xSeat - 1) { + data.setSx(xPlayer + 1); + } + } + } + + /** + * 集計されたチョコの数のリストを取得 + * + * @return チョコの数のリスト + */ + public List getChocoValues() { + return chocoValues; + } +} + +/** 結果を出力するクラス */ +final class ChocoResult { + public void printResult(List chocoValues) { + for (int value : chocoValues) { + System.out.println(value); + } + } + +} + +public class B136_chocolate { + + public static void main(String[] args) { + final Scanner sc = new Scanner(System.in); + final int movingTime = sc.nextInt(); + final int ySeat = sc.nextInt(); + final int xSeat = sc.nextInt(); + int yPlayer = sc.nextInt(); + int xPlayer = sc.nextInt(); + + sc.nextLine();// 残った改行文字を消費 + + final String movingCommand = sc.nextLine(); + + // HxW のグリッドを宣言し、読み込む + final int[][] chocoNumber = new int[ySeat][xSeat]; + for (int i = 1; i < ySeat; i++) { + for (int j = 1; j < xSeat; j++) { + chocoNumber[i][j] = sc.nextInt(); + } + } + + // チョコデータオブジェクトを生成 + ChocoData data = new ChocoData(movingTime, ySeat, xSeat, yPlayer, xPlayer, movingCommand, chocoNumber); + + // チョコロジックオブジェクトを生成し、コマンドを実行 + ChocoLogic chocoLogic = new ChocoLogic(data); + chocoLogic.Commands(); + + // チョコ結果オブジェクトを生成し、結果を出力 + ChocoResult chocoResult = new ChocoResult(); + chocoResult.printResult(chocoLogic.getChocoValues()); + + sc.close(); + + } +} diff --git a/rsuzuki/src/C021_storm.java b/rsuzuki/src/C021_storm.java deleted file mode 100644 index c309b79..0000000 --- a/rsuzuki/src/C021_storm.java +++ /dev/null @@ -1,90 +0,0 @@ -package paiza_c; - -import java.util.Scanner; - -/** - * 台風の情報を保持し、暴風域判定ロジックを提供するクラス - */ -class Typhoon { - /** 台風の中心X座標 */ - private final int centerX; - /** 台風の中心Y座標 */ - private final int centerY; - /** 内円の半径の2乗 */ - private final int inRadiusSq; - /** 外円の半径の2乗 */ - private final int outRadiusSq; - - /** - * @param centerX 台風の中心X座標 - * @param centerY 台風の中心Y座標 - * @param innerRadius 内円の半径 - * @param outerRadius 外円の半径 - */ - public Typhoon(int centerX, int centerY, int inRadius, int outRadius) { - this.centerX = centerX; - this.centerY = centerY; - this.inRadiusSq = inRadius * inRadius; - this.outRadiusSq = outRadius * outRadius; - } - - /** - * 指定された座標がこの台風の暴風域内にあるかどうかを判定 - * - * @param pointX 判定対象のX座標 - * @param pointY 判定対象のY座標 - * @return 座標が暴風域内にある場合はtrue、そうでない場合はfalse - */ - public boolean isInStormRange(int pointX, int pointY) { - // 台風の中心から指定された地点までの距離の2乗を計算 - int distanceStormSq = (pointX - centerX) * (pointX - centerX) + (pointY - centerY) * (pointY - centerY); - // 距離の2乗が内円の半径の2乗以上、かつ外円の半径の2乗以下であれば暴風域内 - return inRadiusSq <= distanceStormSq && distanceStormSq <= outRadiusSq; - } -} - -public class C021_storm { - public static void main(String[] args) { - Scanner scanner = new Scanner(System.in); - - Typhoon currentTyphoon = readTyphoonData(scanner); - int numberOfPeople = scanner.nextInt(); - PeopleStormCheck(scanner, currentTyphoon, numberOfPeople); - - scanner.close(); - } - - /** - * 標準入力から台風の中心座標と半径を読み込み、Typhoonオブジェクトを生成して返す - * - * @param scanner 標準入力からの読み込みに使用するScannerオブジェクト - * @return 読み込んだデータに基づいて生成されたTyphoonオブジェクト - */ - private static Typhoon readTyphoonData(Scanner scanner) { - final int xc = scanner.nextInt(); - final int yc = scanner.nextInt(); - final int r_1 = scanner.nextInt(); - final int r_2 = scanner.nextInt(); - return new Typhoon(xc, yc, r_1, r_2); - } - - /** - * 標準入力から指定された人数の座標を読み込み、 それぞれの座標が与えられた台風の暴風域内にあるかを判定し、結果を標準出力に出す - * - * @param scanner 標準入力からの読み込みに使用するScannerオブジェクト - * @param typhoon 判定に使用するTyphoonオブジェクト - * @param numberOfPeople 判定する人の数 - */ - private static void PeopleStormCheck(Scanner scanner, Typhoon typhoon, int numberOfPeople) { - for (int i = 0; i < numberOfPeople; i++) { - final int personX = scanner.nextInt(); - final int personY = scanner.nextInt(); - - if (typhoon.isInStormRange(personX, personY)) { - System.out.println("yes"); - } else { - System.out.println("no"); - } - } - } -} -- GitLab From 1ccb6f234357c84d0aece34f1238b59a86db0176 Mon Sep 17 00:00:00 2001 From: ryouji Date: Tue, 8 Jul 2025 13:13:57 +0900 Subject: [PATCH 15/19] =?UTF-8?q?paiza=E3=81=AEB158:=E7=9F=B3=E3=81=AE?= =?UTF-8?q?=E7=A9=8D=E3=81=BE=E3=82=8C=E3=81=9F=E9=83=A8=E5=B1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rsuzuki/src/B136_chocolate.java | 190 -------------------------------- rsuzuki/src/B158_stone.java | 107 ++++++++++++++++++ 2 files changed, 107 insertions(+), 190 deletions(-) delete mode 100644 rsuzuki/src/B136_chocolate.java create mode 100644 rsuzuki/src/B158_stone.java diff --git a/rsuzuki/src/B136_chocolate.java b/rsuzuki/src/B136_chocolate.java deleted file mode 100644 index df80074..0000000 --- a/rsuzuki/src/B136_chocolate.java +++ /dev/null @@ -1,190 +0,0 @@ -package paiza_c; - -import java.util.ArrayList; -import java.util.List; -import java.util.Scanner; - -/** データを保持するクラス */ -final class ChocoData { - /** 移動回数 */ - private final int movingTime; - /** 縦の席数 */ - private final int ySeat; - /** 横の席数 */ - private final int xSeat; - /** 自分の座席がどこか */ - private int yPlayer; - private int xPlayer; - /** 移動経路FBLR */ - private final String movingCommand; - /** 座席でもらえるチョコの数を格納する配列 */ - final int[][] chocoNumber; - - /** - * ChocoDataの新しいインスタンスを生成 - * - * @param movingTime 移動回数 - * @param ySeat 縦の席数 - * @param xSeat 横の席数 - * @param yPlayer プレイヤーの初期縦位置 - * @param xPlayer プレイヤーの初期横位置 - * @param movingCommand 移動コマンド文字列 - * @param chocoNumber 各座席のチョコの数を格納する二次元配列 - */ - public ChocoData(int movingTime, int ySeat, int xSeat, int yPlayer, int xPlayer, String movingCommand, - int[][] chocoNumber) { - this.movingTime = movingTime; - this.ySeat = ySeat; - this.xSeat = xSeat; - this.yPlayer = yPlayer; - this.xPlayer = xPlayer; - this.movingCommand = movingCommand; - this.chocoNumber = chocoNumber; - } - - public int getMovingTime() { - return movingTime; - } - - public int getYSear() { - return ySeat; - } - - public int getXSeat() { - return xSeat; - } - - public int getYPlayer() { - return yPlayer; - } - - public int getXPlayer() { - return xPlayer; - } - - public String getMovingCommand() { - return movingCommand; - } - - public int getChocoNumber(int y, int x) { - return chocoNumber[y][x]; - } - - public void setSy(int sy) { - this.yPlayer = sy; - } - - public void setSx(int sx) { - this.xPlayer = sx; - } -} - -/** - * ロジック - */ -final class ChocoLogic { - private final ChocoData data; - /** 集計用リスト */ - private final List chocoValues; - - public ChocoLogic(ChocoData data) { - this.data = data; - this.chocoValues = new ArrayList<>(); - } - - /** - * 移動コマンドに基づいてプレイヤーを移動させ、通過した座席のチョコの数を集計 - */ - public void Commands() { - for (int i = 0; i < data.getMovingTime(); i++) { - char command = data.getMovingCommand().charAt(i); - movePlayer(command); - chocoValues.add(data.getChocoNumber(data.getYPlayer(), data.getXPlayer())); - } - } - - /** - * 指定されたコマンドに基づいてプレイヤーを移動 - */ - private void movePlayer(char command) { - int yPlayer = data.getYPlayer(); - int xPlayer = data.getXPlayer(); - int ySeat = data.getYSear(); - int xSeat = data.getXSeat(); - - if (command == 'F') { // 前進 (上) - if (yPlayer > 0) { - data.setSy(yPlayer - 1); - } - } else if (command == 'B') { // 後退 (下) - if (yPlayer < ySeat - 1) { - data.setSy(yPlayer + 1); - } - } else if (command == 'L') { // 左 - if (xPlayer > 0) { - data.setSx(xPlayer - 1); - } - } else if (command == 'R') { // 右 - if (xPlayer < xSeat - 1) { - data.setSx(xPlayer + 1); - } - } - } - - /** - * 集計されたチョコの数のリストを取得 - * - * @return チョコの数のリスト - */ - public List getChocoValues() { - return chocoValues; - } -} - -/** 結果を出力するクラス */ -final class ChocoResult { - public void printResult(List chocoValues) { - for (int value : chocoValues) { - System.out.println(value); - } - } - -} - -public class B136_chocolate { - - public static void main(String[] args) { - final Scanner sc = new Scanner(System.in); - final int movingTime = sc.nextInt(); - final int ySeat = sc.nextInt(); - final int xSeat = sc.nextInt(); - int yPlayer = sc.nextInt(); - int xPlayer = sc.nextInt(); - - sc.nextLine();// 残った改行文字を消費 - - final String movingCommand = sc.nextLine(); - - // HxW のグリッドを宣言し、読み込む - final int[][] chocoNumber = new int[ySeat][xSeat]; - for (int i = 1; i < ySeat; i++) { - for (int j = 1; j < xSeat; j++) { - chocoNumber[i][j] = sc.nextInt(); - } - } - - // チョコデータオブジェクトを生成 - ChocoData data = new ChocoData(movingTime, ySeat, xSeat, yPlayer, xPlayer, movingCommand, chocoNumber); - - // チョコロジックオブジェクトを生成し、コマンドを実行 - ChocoLogic chocoLogic = new ChocoLogic(data); - chocoLogic.Commands(); - - // チョコ結果オブジェクトを生成し、結果を出力 - ChocoResult chocoResult = new ChocoResult(); - chocoResult.printResult(chocoLogic.getChocoValues()); - - sc.close(); - - } -} diff --git a/rsuzuki/src/B158_stone.java b/rsuzuki/src/B158_stone.java new file mode 100644 index 0000000..8523cb7 --- /dev/null +++ b/rsuzuki/src/B158_stone.java @@ -0,0 +1,107 @@ +package paiza_c; + +import java.util.Scanner; + +/** データを保持するクラス */ +final class StoneData { + private final int boardNumber; + private final int[][] stoneAmount; + + /** + * インスタンスを生成 + * + * @param boardNumber 入力される一辺の板の数 + * @param stoneNumber 入力される石の数 + */ + public StoneData(int boardNumber, int[][] stoneAmount) { + this.boardNumber = boardNumber; + this.stoneAmount = stoneAmount; + } + + public int getBoardNumber() { + return boardNumber; + } + + public int getStoneAmount(int y, int x) { + return stoneAmount[y][x]; + } +} + +/** + * ロジック + * + */ +final class StoneLogic { + /** + * 盤面上の石の総数を計算し、各位置で取り除く必要のある石の数を合計して返す + * + * @param stoneData 石のデータを含むStoneDataオブジェクト + * @param boardNumber 石の行列 + * @return 取り除く必要のある石の合計数 + */ + public int calculateTotalStoneToRemove(StoneData stoneData) { + int totalStoneRemove = 0; + int boardNumber = stoneData.getBoardNumber(); + + for (int i = 0; i < boardNumber; i++) { + for (int j = 0; j < boardNumber; j++) { + // 1-indexed (1からN) の座標に変換 + int row = i + 1; + int col = j + 1; + + // プレートが属するレイヤー番号を計算 + // レイヤー番号は、外側のレイヤーから内側に向かって1から(N+1)/2まで + int layer = Math.min(Math.min(row, col), Math.min(boardNumber - row + 1, boardNumber - col + 1)); + + // そのプレートに必要な石の数を計算 + int requiredStones = layer; + + // 現在の場所の石の数 + int currentStones = stoneData.getStoneAmount(i, j); + + // 取り除く必要のある石の数を計算し、合計に追加 + totalStoneRemove += (currentStones - requiredStones); + } + } + return totalStoneRemove; + } +} + +/** + * 結果に集計するクラス final class StoneResult { private int totalStone; + * + * public StoneResult() { this.totalStone = 0; } + * + * // 勝利数をインクリメントする public void incrementresult() { this.totalStone++; } + * + * // 現在の勝利数を取得する public int getStoneResult() { return totalStone; } + * + * } + */ + +/** メイン */ +public class B158_stone { + + public static void main(String[] args) { + final Scanner sc = new Scanner(System.in); + final int boardNumber = sc.nextInt(); + + final int stoneAmount[][] = new int[boardNumber][boardNumber]; + for (int i = 0; i < boardNumber; i++) { + for (int j = 0; j < boardNumber; j++) { + stoneAmount[i][j] = sc.nextInt(); + } + } + + sc.close(); + + StoneLogic stoneLogic = new StoneLogic(); + StoneData stoneData = new StoneData(boardNumber, stoneAmount); + // StoneResult stoneResult = new StoneResult(); + + // System.out.println(stoneResult.getStoneResult()); + System.out.println(stoneLogic.calculateTotalStoneToRemove(stoneData)); + + } + +} -- GitLab From 0c2bf5636a6a733ad3d1d7dfc5d7bd581591d456 Mon Sep 17 00:00:00 2001 From: ryouji Date: Tue, 8 Jul 2025 14:50:35 +0900 Subject: [PATCH 16/19] =?UTF-8?q?paiza=E3=81=AEC021:=E6=9A=B4=E9=A2=A8?= =?UTF-8?q?=E5=9F=9F=E3=81=AB=E3=81=84=E3=81=BE=E3=81=99=E3=81=8B=EF=BC=9F?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A32?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rsuzuki/src/B158_stone.java | 107 ------------------------------------ rsuzuki/src/C021_storm.java | 92 +++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 107 deletions(-) delete mode 100644 rsuzuki/src/B158_stone.java create mode 100644 rsuzuki/src/C021_storm.java diff --git a/rsuzuki/src/B158_stone.java b/rsuzuki/src/B158_stone.java deleted file mode 100644 index 8523cb7..0000000 --- a/rsuzuki/src/B158_stone.java +++ /dev/null @@ -1,107 +0,0 @@ -package paiza_c; - -import java.util.Scanner; - -/** データを保持するクラス */ -final class StoneData { - private final int boardNumber; - private final int[][] stoneAmount; - - /** - * インスタンスを生成 - * - * @param boardNumber 入力される一辺の板の数 - * @param stoneNumber 入力される石の数 - */ - public StoneData(int boardNumber, int[][] stoneAmount) { - this.boardNumber = boardNumber; - this.stoneAmount = stoneAmount; - } - - public int getBoardNumber() { - return boardNumber; - } - - public int getStoneAmount(int y, int x) { - return stoneAmount[y][x]; - } -} - -/** - * ロジック - * - */ -final class StoneLogic { - /** - * 盤面上の石の総数を計算し、各位置で取り除く必要のある石の数を合計して返す - * - * @param stoneData 石のデータを含むStoneDataオブジェクト - * @param boardNumber 石の行列 - * @return 取り除く必要のある石の合計数 - */ - public int calculateTotalStoneToRemove(StoneData stoneData) { - int totalStoneRemove = 0; - int boardNumber = stoneData.getBoardNumber(); - - for (int i = 0; i < boardNumber; i++) { - for (int j = 0; j < boardNumber; j++) { - // 1-indexed (1からN) の座標に変換 - int row = i + 1; - int col = j + 1; - - // プレートが属するレイヤー番号を計算 - // レイヤー番号は、外側のレイヤーから内側に向かって1から(N+1)/2まで - int layer = Math.min(Math.min(row, col), Math.min(boardNumber - row + 1, boardNumber - col + 1)); - - // そのプレートに必要な石の数を計算 - int requiredStones = layer; - - // 現在の場所の石の数 - int currentStones = stoneData.getStoneAmount(i, j); - - // 取り除く必要のある石の数を計算し、合計に追加 - totalStoneRemove += (currentStones - requiredStones); - } - } - return totalStoneRemove; - } -} - -/** - * 結果に集計するクラス final class StoneResult { private int totalStone; - * - * public StoneResult() { this.totalStone = 0; } - * - * // 勝利数をインクリメントする public void incrementresult() { this.totalStone++; } - * - * // 現在の勝利数を取得する public int getStoneResult() { return totalStone; } - * - * } - */ - -/** メイン */ -public class B158_stone { - - public static void main(String[] args) { - final Scanner sc = new Scanner(System.in); - final int boardNumber = sc.nextInt(); - - final int stoneAmount[][] = new int[boardNumber][boardNumber]; - for (int i = 0; i < boardNumber; i++) { - for (int j = 0; j < boardNumber; j++) { - stoneAmount[i][j] = sc.nextInt(); - } - } - - sc.close(); - - StoneLogic stoneLogic = new StoneLogic(); - StoneData stoneData = new StoneData(boardNumber, stoneAmount); - // StoneResult stoneResult = new StoneResult(); - - // System.out.println(stoneResult.getStoneResult()); - System.out.println(stoneLogic.calculateTotalStoneToRemove(stoneData)); - - } - -} diff --git a/rsuzuki/src/C021_storm.java b/rsuzuki/src/C021_storm.java new file mode 100644 index 0000000..5f03f8d --- /dev/null +++ b/rsuzuki/src/C021_storm.java @@ -0,0 +1,92 @@ +package paiza_c; + +import java.util.Scanner; + +/** + * 台風の情報を保持し、暴風域判定ロジックを提供するクラス + */ +class Typhoon { + /** 台風の中心X座標 */ + private final int centerX; + /** 台風の中心Y座標 */ + private final int centerY; + /** 内円の半径の2乗 */ + private final int inRadiusSq; + /** 外円の半径の2乗 */ + private final int outRadiusSq; + + /** + * @param centerX 台風の中心X座標 + * @param centerY 台風の中心Y座標 + * @param inRadius 内円の半径 + * @param outRadius 外円の半径 + */ + public Typhoon(int centerX, int centerY, int inRadius, int outRadius) { + this.centerX = centerX; + this.centerY = centerY; + this.inRadiusSq = inRadius * inRadius; + this.outRadiusSq = outRadius * outRadius; + } + + /** + * 指定された座標がこの台風の暴風域内にあるかどうかを判定 + * + * @param pointX 判定対象のX座標 + * @param pointY 判定対象のY座標 + * @return 座標が暴風域内にある場合はtrue、そうでない場合はfalse + */ + public boolean isInStormRange(int pointX, int pointY) { + // 台風の中心から指定された地点までの距離の2乗を計算 + final int distanceStormSq = (pointX - centerX) * (pointX - centerX) + (pointY - centerY) * (pointY - centerY); + // 距離の2乗が内円の半径の2乗以上、かつ外円の半径の2乗以下であれば暴風域内 + return inRadiusSq <= distanceStormSq && distanceStormSq <= outRadiusSq; + } +} + +/** + * 暴風域判定の結果を標準出力に出力する + * + * @param isInStormRange 暴風域内にあるかどうかの判定結果 + */ +final class PrintStorm { + public static void stormRangeResult(final boolean isInStormRange) { + if (isInStormRange) { + System.out.println("yes"); + } else { + System.out.println("no"); + } + } +} + +public class C021_storm { + public static void main(String[] args) { + final Scanner scanner = new Scanner(System.in); + + final Typhoon typhoon = readTyphoonData(scanner); + final int numberOfPeople = scanner.nextInt(); + + for (int i = 0; i < numberOfPeople; i++) { + final int personX = scanner.nextInt(); + final int personY = scanner.nextInt(); + + final boolean isInStorm = typhoon.isInStormRange(personX, personY); + PrintStorm.stormRangeResult(isInStorm); + } + scanner.close(); + } + + /** + * 標準入力から台風の中心座標と半径を読み込み、Typhoonオブジェクトを生成して返す + * + * @param scanner 標準入力からの読み込みに使用するScannerオブジェクト + * @return 読み込んだデータに基づいて生成されたTyphoonオブジェクト + */ + private static Typhoon readTyphoonData(Scanner scanner) { + final int xc = scanner.nextInt(); + final int yc = scanner.nextInt(); + final int r_1 = scanner.nextInt(); + final int r_2 = scanner.nextInt(); + return new Typhoon(xc, yc, r_1, r_2); + } + +} -- GitLab From dcc17c4feba010226c87f456ecec4fbf9fb2c4ee Mon Sep 17 00:00:00 2001 From: ryouji Date: Tue, 8 Jul 2025 15:18:55 +0900 Subject: [PATCH 17/19] =?UTF-8?q?paiza=E3=81=AEB158:=E7=9F=B3=E3=81=AE?= =?UTF-8?q?=E7=A9=8D=E3=81=BE=E3=82=8C=E3=81=9F=E9=83=A8=E5=B1=8B=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rsuzuki/src/B158_stone.java | 92 +++++++++++++++++++++++++++++++++++++ rsuzuki/src/C021_storm.java | 92 ------------------------------------- 2 files changed, 92 insertions(+), 92 deletions(-) create mode 100644 rsuzuki/src/B158_stone.java delete mode 100644 rsuzuki/src/C021_storm.java diff --git a/rsuzuki/src/B158_stone.java b/rsuzuki/src/B158_stone.java new file mode 100644 index 0000000..6da7cf0 --- /dev/null +++ b/rsuzuki/src/B158_stone.java @@ -0,0 +1,92 @@ +package paiza_c; + +import java.util.Scanner; + +/** データを保持するクラス */ +final class StoneData { + private final int boardNumber; + private final int[][] stoneAmount; + + /** + * インスタンスを生成 + * + * @param boardNumber 入力される一辺の板の数 + * @param stoneNumber 入力される石の数 + */ + public StoneData(int boardNumber, int[][] stoneAmount) { + this.boardNumber = boardNumber; + this.stoneAmount = stoneAmount; + } + + public int getBoardNumber() { + return boardNumber; + } + + public int getStoneAmount(int y, int x) { + return stoneAmount[y][x]; + } +} + +/** + * ロジック + * + */ +final class StoneLogic { + /** + * 盤面上の石の総数を計算し、各位置で取り除く必要のある石の数を合計して返す + * + * @param stoneData 石のデータを含むStoneDataオブジェクト + * @return 取り除く必要のある石の合計数 + */ + public int calculateTotalStoneToRemove(StoneData stoneData) { + int totalStoneRemove = 0; + int boardNumber = stoneData.getBoardNumber();// stoneDataから取得 + + for (int i = 0; i < boardNumber; i++) { + for (int j = 0; j < boardNumber; j++) { + // 配列のインデックス (0から始まる) を、計算で使用する1から始まる座標に変換 + int row = i + 1; + int col = j + 1; + + // プレートが属するレイヤー番号を計算 + // レイヤー番号は、外側のレイヤーから内側に向かって1から(N+1)/2まで + int layer = Math.min(Math.min(row, col), Math.min(boardNumber - row + 1, boardNumber - col + 1)); + + // そのプレートに必要な石の数を計算 + int requiredStones = layer; + + // 現在の場所の石の数 + int currentStones = stoneData.getStoneAmount(i, j); + + // 取り除く必要のある石の数を計算し、合計に追加 + totalStoneRemove += (currentStones - requiredStones); + } + } + return totalStoneRemove; + } +} + +/** メイン */ +public class B158_stone { + + public static void main(String[] args) { + final Scanner sc = new Scanner(System.in); + final int boardNumber = sc.nextInt(); + + final int stoneAmount[][] = new int[boardNumber][boardNumber]; + for (int i = 0; i < boardNumber; i++) { + for (int j = 0; j < boardNumber; j++) { + stoneAmount[i][j] = sc.nextInt(); + } + } + + sc.close(); + + final StoneLogic stoneLogic = new StoneLogic(); + final StoneData stoneData = new StoneData(boardNumber, stoneAmount); + + System.out.println(stoneLogic.calculateTotalStoneToRemove(stoneData)); + + } + +} diff --git a/rsuzuki/src/C021_storm.java b/rsuzuki/src/C021_storm.java deleted file mode 100644 index 5f03f8d..0000000 --- a/rsuzuki/src/C021_storm.java +++ /dev/null @@ -1,92 +0,0 @@ -package paiza_c; - -import java.util.Scanner; - -/** - * 台風の情報を保持し、暴風域判定ロジックを提供するクラス - */ -class Typhoon { - /** 台風の中心X座標 */ - private final int centerX; - /** 台風の中心Y座標 */ - private final int centerY; - /** 内円の半径の2乗 */ - private final int inRadiusSq; - /** 外円の半径の2乗 */ - private final int outRadiusSq; - - /** - * @param centerX 台風の中心X座標 - * @param centerY 台風の中心Y座標 - * @param inRadius 内円の半径 - * @param outRadius 外円の半径 - */ - public Typhoon(int centerX, int centerY, int inRadius, int outRadius) { - this.centerX = centerX; - this.centerY = centerY; - this.inRadiusSq = inRadius * inRadius; - this.outRadiusSq = outRadius * outRadius; - } - - /** - * 指定された座標がこの台風の暴風域内にあるかどうかを判定 - * - * @param pointX 判定対象のX座標 - * @param pointY 判定対象のY座標 - * @return 座標が暴風域内にある場合はtrue、そうでない場合はfalse - */ - public boolean isInStormRange(int pointX, int pointY) { - // 台風の中心から指定された地点までの距離の2乗を計算 - final int distanceStormSq = (pointX - centerX) * (pointX - centerX) + (pointY - centerY) * (pointY - centerY); - // 距離の2乗が内円の半径の2乗以上、かつ外円の半径の2乗以下であれば暴風域内 - return inRadiusSq <= distanceStormSq && distanceStormSq <= outRadiusSq; - } -} - -/** - * 暴風域判定の結果を標準出力に出力する - * - * @param isInStormRange 暴風域内にあるかどうかの判定結果 - */ -final class PrintStorm { - public static void stormRangeResult(final boolean isInStormRange) { - if (isInStormRange) { - System.out.println("yes"); - } else { - System.out.println("no"); - } - } -} - -public class C021_storm { - public static void main(String[] args) { - final Scanner scanner = new Scanner(System.in); - - final Typhoon typhoon = readTyphoonData(scanner); - final int numberOfPeople = scanner.nextInt(); - - for (int i = 0; i < numberOfPeople; i++) { - final int personX = scanner.nextInt(); - final int personY = scanner.nextInt(); - - final boolean isInStorm = typhoon.isInStormRange(personX, personY); - PrintStorm.stormRangeResult(isInStorm); - } - scanner.close(); - } - - /** - * 標準入力から台風の中心座標と半径を読み込み、Typhoonオブジェクトを生成して返す - * - * @param scanner 標準入力からの読み込みに使用するScannerオブジェクト - * @return 読み込んだデータに基づいて生成されたTyphoonオブジェクト - */ - private static Typhoon readTyphoonData(Scanner scanner) { - final int xc = scanner.nextInt(); - final int yc = scanner.nextInt(); - final int r_1 = scanner.nextInt(); - final int r_2 = scanner.nextInt(); - return new Typhoon(xc, yc, r_1, r_2); - } - -} -- GitLab From 8b9d06c962f3633600b9d029adfeeeee3372917c Mon Sep 17 00:00:00 2001 From: ryouji Date: Fri, 18 Jul 2025 17:34:06 +0900 Subject: [PATCH 18/19] =?UTF-8?q?paiza=E3=81=AEB136:=E3=83=81=E3=83=A7?= =?UTF-8?q?=E3=82=B3=E3=81=AE=E3=81=8A=E8=BF=94=E3=81=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rsuzuki/src/B136_chocolate.java | 190 ++++++++++++++++++++++++++++++++ rsuzuki/src/B158_stone.java | 92 ---------------- rsuzuki/src/ChocoTest.java | 109 ++++++++++++++++++ 3 files changed, 299 insertions(+), 92 deletions(-) create mode 100644 rsuzuki/src/B136_chocolate.java delete mode 100644 rsuzuki/src/B158_stone.java create mode 100644 rsuzuki/src/ChocoTest.java diff --git a/rsuzuki/src/B136_chocolate.java b/rsuzuki/src/B136_chocolate.java new file mode 100644 index 0000000..d3d3b86 --- /dev/null +++ b/rsuzuki/src/B136_chocolate.java @@ -0,0 +1,190 @@ +package paiza_c; + +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +/** データを保持するクラス */ +final class ChocoData { + /** 移動回数 */ + private final int movingTime; + /** 縦の席数 */ + private final int ySeat; + /** 横の席数 */ + private final int xSeat; + /** 自分の座席がどこか */ + private int yPlayer; + private int xPlayer; + /** 移動経路FBLR */ + private final String movingCommand; + /** 座席でもらえるチョコの数を格納する配列 */ + final int[][] chocoNumber; + + /** + * ChocoDataの新しいインスタンスを生成 + * + * @param movingTime 移動回数 + * @param ySeat 縦の席数 + * @param xSeat 横の席数 + * @param yPlayer プレイヤーの初期縦位置 + * @param xPlayer プレイヤーの初期横位置 + * @param movingCommand 移動コマンド文字列 + * @param chocoNumber 各座席のチョコの数を格納する二次元配列 + */ + public ChocoData(int movingTime, int ySeat, int xSeat, int yPlayer, int xPlayer, String movingCommand, + int[][] chocoNumber) { + this.movingTime = movingTime; + this.ySeat = ySeat; + this.xSeat = xSeat; + this.yPlayer = yPlayer; + this.xPlayer = xPlayer; + this.movingCommand = movingCommand; + this.chocoNumber = chocoNumber; + } + + public int getMovingTime() { + return movingTime; + } + + public int getYSeat() { + return ySeat; + } + + public int getXSeat() { + return xSeat; + } + + public int getYPlayer() { + return yPlayer; + } + + public int getXPlayer() { + return xPlayer; + } + + public String getMovingCommand() { + return movingCommand; + } + + public int getChocoNumber(int y, int x) { + return chocoNumber[y][x]; + } + + public void setSy(int sy) { + this.yPlayer = sy; + } + + public void setSx(int sx) { + this.xPlayer = sx; + } +} + +/** + * ロジック + */ +final class ChocoLogic { + private final ChocoData data; + /** 集計用リスト */ + private final List chocoValues; + + public ChocoLogic(ChocoData data) { + this.data = data; + this.chocoValues = new ArrayList<>(); + } + + /** + * 移動コマンドに基づいてプレイヤーを移動させ、通過した座席のチョコの数を集計 + */ + public void Commands() { + for (int i = 0; i < data.getMovingTime(); i++) { + char command = data.getMovingCommand().charAt(i); + movePlayer(command); + chocoValues.add(data.getChocoNumber(data.getYPlayer(), data.getXPlayer())); + } + } + + /** + * 指定されたコマンドに基づいてプレイヤーを移動 + */ + private void movePlayer(char command) { + int yPlayer = data.getYPlayer(); + int xPlayer = data.getXPlayer(); + int ySeat = data.getYSeat(); + int xSeat = data.getXSeat(); + + if (command == 'F') { // 前進 (上) + if (yPlayer > 0) { + data.setSy(yPlayer - 1); + } + } else if (command == 'B') { // 後退 (下) + if (yPlayer < ySeat - 1) { + data.setSy(yPlayer + 1); + } + } else if (command == 'L') { // 左 + if (xPlayer > 0) { + data.setSx(xPlayer - 1); + } + } else if (command == 'R') { // 右 + if (xPlayer < xSeat - 1) { + data.setSx(xPlayer + 1); + } + } + } + + /** + * 集計されたチョコの数のリストを取得 + * + * @return チョコの数のリスト + */ + public List getChocoValues() { + return chocoValues; + } +} + +/** 結果を出力するクラス */ +final class ChocoResult { + public void printResult(List chocoValues) { + for (int value : chocoValues) { + System.out.println(value); + } + } + +} + +public class B136_chocolate { + + public static void main(String[] args) { + final Scanner sc = new Scanner(System.in); + final int movingTime = sc.nextInt(); + final int ySeat = sc.nextInt(); + final int xSeat = sc.nextInt(); + int yPlayer = sc.nextInt(); + int xPlayer = sc.nextInt(); + + sc.nextLine();// 残った改行文字を消費 + + final String movingCommand = sc.nextLine(); + + // HxW のグリッドを宣言し、読み込む + final int[][] chocoNumber = new int[ySeat][xSeat]; + for (int i = 1; i < ySeat; i++) { + for (int j = 1; j < xSeat; j++) { + chocoNumber[i][j] = sc.nextInt(); + } + } + + // チョコデータオブジェクトを生成 + ChocoData data = new ChocoData(movingTime, ySeat, xSeat, yPlayer, xPlayer, movingCommand, chocoNumber); + + // チョコロジックオブジェクトを生成し、コマンドを実行 + ChocoLogic chocoLogic = new ChocoLogic(data); + chocoLogic.Commands(); + + // チョコ結果オブジェクトを生成し、結果を出力 + ChocoResult chocoResult = new ChocoResult(); + chocoResult.printResult(chocoLogic.getChocoValues()); + + sc.close(); + + } +} diff --git a/rsuzuki/src/B158_stone.java b/rsuzuki/src/B158_stone.java deleted file mode 100644 index 6da7cf0..0000000 --- a/rsuzuki/src/B158_stone.java +++ /dev/null @@ -1,92 +0,0 @@ -package paiza_c; - -import java.util.Scanner; - -/** データを保持するクラス */ -final class StoneData { - private final int boardNumber; - private final int[][] stoneAmount; - - /** - * インスタンスを生成 - * - * @param boardNumber 入力される一辺の板の数 - * @param stoneNumber 入力される石の数 - */ - public StoneData(int boardNumber, int[][] stoneAmount) { - this.boardNumber = boardNumber; - this.stoneAmount = stoneAmount; - } - - public int getBoardNumber() { - return boardNumber; - } - - public int getStoneAmount(int y, int x) { - return stoneAmount[y][x]; - } -} - -/** - * ロジック - * - */ -final class StoneLogic { - /** - * 盤面上の石の総数を計算し、各位置で取り除く必要のある石の数を合計して返す - * - * @param stoneData 石のデータを含むStoneDataオブジェクト - * @return 取り除く必要のある石の合計数 - */ - public int calculateTotalStoneToRemove(StoneData stoneData) { - int totalStoneRemove = 0; - int boardNumber = stoneData.getBoardNumber();// stoneDataから取得 - - for (int i = 0; i < boardNumber; i++) { - for (int j = 0; j < boardNumber; j++) { - // 配列のインデックス (0から始まる) を、計算で使用する1から始まる座標に変換 - int row = i + 1; - int col = j + 1; - - // プレートが属するレイヤー番号を計算 - // レイヤー番号は、外側のレイヤーから内側に向かって1から(N+1)/2まで - int layer = Math.min(Math.min(row, col), Math.min(boardNumber - row + 1, boardNumber - col + 1)); - - // そのプレートに必要な石の数を計算 - int requiredStones = layer; - - // 現在の場所の石の数 - int currentStones = stoneData.getStoneAmount(i, j); - - // 取り除く必要のある石の数を計算し、合計に追加 - totalStoneRemove += (currentStones - requiredStones); - } - } - return totalStoneRemove; - } -} - -/** メイン */ -public class B158_stone { - - public static void main(String[] args) { - final Scanner sc = new Scanner(System.in); - final int boardNumber = sc.nextInt(); - - final int stoneAmount[][] = new int[boardNumber][boardNumber]; - for (int i = 0; i < boardNumber; i++) { - for (int j = 0; j < boardNumber; j++) { - stoneAmount[i][j] = sc.nextInt(); - } - } - - sc.close(); - - final StoneLogic stoneLogic = new StoneLogic(); - final StoneData stoneData = new StoneData(boardNumber, stoneAmount); - - System.out.println(stoneLogic.calculateTotalStoneToRemove(stoneData)); - - } - -} diff --git a/rsuzuki/src/ChocoTest.java b/rsuzuki/src/ChocoTest.java new file mode 100644 index 0000000..b4eccc3 --- /dev/null +++ b/rsuzuki/src/ChocoTest.java @@ -0,0 +1,109 @@ +package paiza_c; + +import static org.junit.Assert.*; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.util.Arrays; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; + +public class ChocoTest { + + // ChocoData クラスのテスト + public static class ChocoDataTest { + + private ChocoData chocoData; + private int[][] chocoNumbers; + + @Before + public void setUp() { + chocoNumbers = new int[][] { { 3, 6, 2 }, { 0, 4, 1 }, { 5, 0, 7 } }; + chocoData = new ChocoData(3, 3, 3, 2, 1, "FRB", chocoNumbers); + } + + @Test + public void testConstructorAndGetters() { + assertEquals(3, chocoData.getMovingTime()); + assertEquals(3, chocoData.getYSeat()); + assertEquals(3, chocoData.getXSeat()); + assertEquals(2, chocoData.getYPlayer()); + assertEquals(1, chocoData.getXPlayer()); + assertEquals("FRB", chocoData.getMovingCommand()); + assertEquals(4, chocoData.getChocoNumber(1, 1)); + assertEquals(0, chocoData.getChocoNumber(2, 1)); + } + + @Test + public void testSetPlayerCoordinates() { + chocoData.setSy(2); + chocoData.setSx(1); + assertEquals(2, chocoData.getYPlayer()); + assertEquals(1, chocoData.getXPlayer()); + } + } + + // ChocoLogic クラスのテスト + public static class ChocoLogicTest { + + private ChocoData chocoData; + private ChocoLogic chocoLogic; + private int[][] chocoNumbers; + + @Before + public void setUp() { + // プレイヤーの初期位置 (1,0) + chocoNumbers = new int[][] { { 3, 6, 2 }, { 0, 4, 1 }, { 5, 0, 7 } }; + } + + @Test + public void testCommandsExecutionAndChocoCollection() { + // 初期位置: (1,0) チョコ: 0 + // コマンド: F (上) -> (0,0) チョコ: 3 + // コマンド: R (右) -> (0,1) チョコ: 6 + // コマンド: B (下) -> (1,1) チョコ: 4 + + chocoData = new ChocoData(3, 3, 3, 1, 0, "FRB", chocoNumbers); + chocoLogic = new ChocoLogic(chocoData); + + chocoLogic.Commands(); + List expectedChocoValues = Arrays.asList(3, 6, 4); + assertEquals(expectedChocoValues, chocoLogic.getChocoValues()); + assertEquals(1, chocoData.getYPlayer()); // 最終的なプレイヤーの位置のY座標 + assertEquals(1, chocoData.getXPlayer()); // 最終的なプレイヤーの位置のX座標 + } + + } + + // ChocoResult クラスのテスト + public static class ChocoResultTest { + + // テスト中にSystem.outの出力をキャプチャするためのByteArrayOutputStream + private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); + // 元のSystem.outを保持するためのPrintStream + private final PrintStream originalOut = System.out; + + @Before + public void setUpStreams() { + System.setOut(new PrintStream(outContent)); + } + + @Test + public void testPrintResult() { + ChocoResult chocoResult = new ChocoResult(); + List testValues = Arrays.asList(100, 200, 300); + chocoResult.printResult(testValues); + + String expectedOutput = "100\n200\n300\n"; + assertEquals(expectedOutput, outContent.toString()); + } + + // 各テストの後に元のSystem.outを復元 + @org.junit.After + public void restoreStreams() { + System.setOut(originalOut); + } + } +} \ No newline at end of file -- GitLab From daa8ad5b24e55eb22689a4a30d397a4f1f780f44 Mon Sep 17 00:00:00 2001 From: ryouji Date: Wed, 23 Jul 2025 15:52:41 +0900 Subject: [PATCH 19/19] =?UTF-8?q?paiza=E3=81=AEB136:=E3=83=81=E3=83=A7?= =?UTF-8?q?=E3=82=B3=E3=81=AE=E3=81=8A=E8=BF=94=E3=81=97=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88=E3=82=B3=E3=83=BC=E3=83=89=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rsuzuki/src/ChocoTest.java | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/rsuzuki/src/ChocoTest.java b/rsuzuki/src/ChocoTest.java index b4eccc3..2e8091b 100644 --- a/rsuzuki/src/ChocoTest.java +++ b/rsuzuki/src/ChocoTest.java @@ -20,12 +20,12 @@ public class ChocoTest { @Before public void setUp() { - chocoNumbers = new int[][] { { 3, 6, 2 }, { 0, 4, 1 }, { 5, 0, 7 } }; chocoData = new ChocoData(3, 3, 3, 2, 1, "FRB", chocoNumbers); } @Test - public void testConstructorAndGetters() { + public void Getterで入力された値を取得できるか() { + chocoNumbers = new int[][] { { 3, 6, 2 }, { 0, 4, 1 }, { 5, 0, 7 } }; assertEquals(3, chocoData.getMovingTime()); assertEquals(3, chocoData.getYSeat()); assertEquals(3, chocoData.getXSeat()); @@ -35,14 +35,6 @@ public class ChocoTest { assertEquals(4, chocoData.getChocoNumber(1, 1)); assertEquals(0, chocoData.getChocoNumber(2, 1)); } - - @Test - public void testSetPlayerCoordinates() { - chocoData.setSy(2); - chocoData.setSx(1); - assertEquals(2, chocoData.getYPlayer()); - assertEquals(1, chocoData.getXPlayer()); - } } // ChocoLogic クラスのテスト @@ -52,19 +44,14 @@ public class ChocoTest { private ChocoLogic chocoLogic; private int[][] chocoNumbers; - @Before - public void setUp() { - // プレイヤーの初期位置 (1,0) - chocoNumbers = new int[][] { { 3, 6, 2 }, { 0, 4, 1 }, { 5, 0, 7 } }; - } - @Test - public void testCommandsExecutionAndChocoCollection() { + public void Logicクラスにおいてコマンドによってチョコを得ることができる() { // 初期位置: (1,0) チョコ: 0 // コマンド: F (上) -> (0,0) チョコ: 3 // コマンド: R (右) -> (0,1) チョコ: 6 // コマンド: B (下) -> (1,1) チョコ: 4 + chocoNumbers = new int[][] { { 3, 6, 2 }, { 0, 4, 1 }, { 5, 0, 7 } }; chocoData = new ChocoData(3, 3, 3, 1, 0, "FRB", chocoNumbers); chocoLogic = new ChocoLogic(chocoData); @@ -75,6 +62,20 @@ public class ChocoTest { assertEquals(1, chocoData.getXPlayer()); // 最終的なプレイヤーの位置のX座標 } + @Test + public void Logicクラスにおいて座席が存在しない時チョコを得ていない() { + // 初期位置: (0,0) チョコ: 0 + // 座席が存在しないので、コマンドを受け取ってもチョコを得られない + chocoNumbers = new int[][] { { 0 } }; + chocoData = new ChocoData(4, 1, 1, 0, 0, "FRBL", chocoNumbers); + chocoLogic = new ChocoLogic(chocoData); + + chocoLogic.Commands(); + List expectedChocoValues = Arrays.asList(0, 0, 0, 0); + assertEquals(expectedChocoValues, chocoLogic.getChocoValues()); + + } + } // ChocoResult クラスのテスト @@ -91,7 +92,7 @@ public class ChocoTest { } @Test - public void testPrintResult() { + public void PrintResultの出力が正しいか() { ChocoResult chocoResult = new ChocoResult(); List testValues = Arrays.asList(100, 200, 300); chocoResult.printResult(testValues); -- GitLab