From 510c8303e8b656f904f7c0162b1daf506e0c0dd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=A4=92=20=E8=80=80=E5=B9=B3?= Date: Thu, 7 Jul 2022 11:25:29 +0900 Subject: [PATCH 1/3] =?UTF-8?q?B099=20=E5=8F=B0=E9=A2=A8=E3=81=AE=E6=8E=A5?= =?UTF-8?q?=E8=BF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ykoiso/src/B099_Typhoon.java | 79 +++++++++++++++++++++++++++++++ ykoiso/test/B099_TyphoonTest.java | 49 +++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 ykoiso/src/B099_Typhoon.java create mode 100644 ykoiso/test/B099_TyphoonTest.java diff --git a/ykoiso/src/B099_Typhoon.java b/ykoiso/src/B099_Typhoon.java new file mode 100644 index 0000000..36e06af --- /dev/null +++ b/ykoiso/src/B099_Typhoon.java @@ -0,0 +1,79 @@ +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +public class B099_Typhoon { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + // 定数の読み込み + final int MAPSIZE = scan.nextInt(); + final int MAXPREAMOUNT = scan.nextInt(); + // マップ + List> Map = new ArrayList<>(); + for (int i = 0; i < MAPSIZE; i++) { + Map.add(new ArrayList<>()); + } + // 行けるかどうかの判定 + // 初期値はtrue + List isGo = new ArrayList<>(); + for (int i = 0; i < MAPSIZE; i++) { + isGo.add(true); + } + // 行ける道のリスト + // 出力用 + List ableLoad = new ArrayList<>(); + + // ブロックごとの降水量の読み込み + for (int i = 0; i < MAPSIZE; i++) { + for (int loadNum = 0; loadNum < MAPSIZE; loadNum++) { + Map.get(loadNum).add(scan.nextInt()); + } + } + + // 行ける道の判定 + calcAbleLoad(isGo, Map, MAPSIZE, MAXPREAMOUNT); + // 行ける道のリストの作成 + makeAbleList(ableLoad, isGo, MAPSIZE); + // 答えの表示 + showAbleLoad(ableLoad); + scan.close(); + } + + // 行ける道の判定 + public static void calcAbleLoad(List isGo, final List> Map, + final int MAPSIZE, final int MAXPREAMOUNT) { + for (int loadBlock = 0; loadBlock < MAPSIZE; loadBlock++) { + for (int loadNum = 0; loadNum < MAPSIZE; loadNum++) { + if (Map.get(loadNum).get(loadBlock) >= MAXPREAMOUNT) { + isGo.set(loadNum, false); + } + } + } + } + + // 行ける道のリストの生成 + public static void makeAbleList(List ableLoad, final List isGo, + final int MAPSIZE) { + for (int i = 0; i < MAPSIZE; i++) { + if (isGo.contains(true)) { + if (isGo.get(i) == true) { + ableLoad.add(i + 1); + } + } + } + } + + // 答えの生成 + public static void showAbleLoad(final List ableLoad) { + if (ableLoad != null) { + for (int i = 0; i < ableLoad.size(); i++) { + System.out.print(ableLoad.get(i)); + if (i != ableLoad.size() - 1) { + System.out.print(" "); + } + } + } else { + System.out.println("wait"); + } + } +} diff --git a/ykoiso/test/B099_TyphoonTest.java b/ykoiso/test/B099_TyphoonTest.java new file mode 100644 index 0000000..394479a --- /dev/null +++ b/ykoiso/test/B099_TyphoonTest.java @@ -0,0 +1,49 @@ +import static org.junit.Assert.assertThat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import org.junit.Before; +import org.junit.Test; +import static org.hamcrest.CoreMatchers.*; + +public class B099_TyphoonTest { + List actual; + List> Map; + + @Before + public void setUp() { + actual = new ArrayList<>(Arrays.asList(true, true, true)); + Map = new ArrayList<>(); + } + + @Test + public void 通れる道が1つのとき() { + Map.add(new ArrayList<>(Arrays.asList(50, 50, 50))); + Map.add(new ArrayList<>(Arrays.asList(150, 50, 50))); + Map.add(new ArrayList<>(Arrays.asList(150, 50, 50))); + B099_Typhoon.calcAbleLoad(actual, Map, 3, 100); + List expected = new ArrayList<>(Arrays.asList(true, false, false)); + assertThat(actual, is(expected)); + } + + @Test + public void 通れる道が3つのとき() { + Map.add(new ArrayList<>(Arrays.asList(50, 50, 50))); + Map.add(new ArrayList<>(Arrays.asList(50, 50, 50))); + Map.add(new ArrayList<>(Arrays.asList(50, 50, 50))); + B099_Typhoon.calcAbleLoad(actual, Map, 3, 100); + List expected = new ArrayList<>(Arrays.asList(true, true, true)); + assertThat(actual, is(expected)); + } + + @Test + public void すべて通れないとき() { + Map.add(new ArrayList<>(Arrays.asList(150, 50, 50))); + Map.add(new ArrayList<>(Arrays.asList(150, 50, 50))); + Map.add(new ArrayList<>(Arrays.asList(150, 50, 50))); + B099_Typhoon.calcAbleLoad(actual, Map, 3, 100); + List expected = new ArrayList<>(Arrays.asList(false, false, false)); + assertThat(actual, is(expected)); + } +} -- GitLab From 70cf9de55a0178b333b1569651ab6ef48650f978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=A4=92=20=E8=80=80=E5=B9=B3?= Date: Thu, 7 Jul 2022 15:01:02 +0900 Subject: [PATCH 2/3] =?UTF-8?q?B099=20=E5=8F=B0=E9=A2=A8=E3=81=AE=E6=8E=A5?= =?UTF-8?q?=E8=BF=91=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ykoiso/src/B099_Typhoon.java | 42 ++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/ykoiso/src/B099_Typhoon.java b/ykoiso/src/B099_Typhoon.java index 36e06af..9953d84 100644 --- a/ykoiso/src/B099_Typhoon.java +++ b/ykoiso/src/B099_Typhoon.java @@ -6,57 +6,57 @@ public class B099_Typhoon { public static void main(String[] args) { Scanner scan = new Scanner(System.in); // 定数の読み込み - final int MAPSIZE = scan.nextInt(); - final int MAXPREAMOUNT = scan.nextInt(); + final int MAP_SIZE = scan.nextInt(); + final int MAX_PRE_AMOUNT = scan.nextInt(); // マップ List> Map = new ArrayList<>(); - for (int i = 0; i < MAPSIZE; i++) { + for (int i = 0; i < MAP_SIZE; i++) { Map.add(new ArrayList<>()); } // 行けるかどうかの判定 // 初期値はtrue - List isGo = new ArrayList<>(); - for (int i = 0; i < MAPSIZE; i++) { - isGo.add(true); + List ListOfIsGo = new ArrayList<>(); + for (int i = 0; i < MAP_SIZE; i++) { + ListOfIsGo.add(true); } // 行ける道のリスト // 出力用 List ableLoad = new ArrayList<>(); // ブロックごとの降水量の読み込み - for (int i = 0; i < MAPSIZE; i++) { - for (int loadNum = 0; loadNum < MAPSIZE; loadNum++) { + for (int i = 0; i < MAP_SIZE; i++) { + for (int loadNum = 0; loadNum < MAP_SIZE; loadNum++) { Map.get(loadNum).add(scan.nextInt()); } } // 行ける道の判定 - calcAbleLoad(isGo, Map, MAPSIZE, MAXPREAMOUNT); + calcAbleLoad(ListOfIsGo, Map, MAP_SIZE, MAX_PRE_AMOUNT); // 行ける道のリストの作成 - makeAbleList(ableLoad, isGo, MAPSIZE); + makeAbleList(ableLoad, ListOfIsGo, MAP_SIZE); // 答えの表示 showAbleLoad(ableLoad); scan.close(); } // 行ける道の判定 - public static void calcAbleLoad(List isGo, final List> Map, - final int MAPSIZE, final int MAXPREAMOUNT) { - for (int loadBlock = 0; loadBlock < MAPSIZE; loadBlock++) { - for (int loadNum = 0; loadNum < MAPSIZE; loadNum++) { - if (Map.get(loadNum).get(loadBlock) >= MAXPREAMOUNT) { - isGo.set(loadNum, false); + public static void calcAbleLoad(List ListOfIsGo, final List> Map, + final int MAP_SIZE, final int MAX_PRE_AMOUNT) { + for (int loadBlock = 0; loadBlock < MAP_SIZE; loadBlock++) { + for (int loadNum = 0; loadNum < MAP_SIZE; loadNum++) { + if (Map.get(loadNum).get(loadBlock) >= MAX_PRE_AMOUNT) { + ListOfIsGo.set(loadNum, false); } } } } // 行ける道のリストの生成 - public static void makeAbleList(List ableLoad, final List isGo, - final int MAPSIZE) { - for (int i = 0; i < MAPSIZE; i++) { - if (isGo.contains(true)) { - if (isGo.get(i) == true) { + public static void makeAbleList(List ableLoad, final List ListOfIsGo, + final int MAP_SIZE) { + for (int i = 0; i < MAP_SIZE; i++) { + if (ListOfIsGo.contains(true)) { + if (ListOfIsGo.get(i) == true) { ableLoad.add(i + 1); } } -- GitLab From e0040dff3ad6468e71ad4996e00d9e6f1c5bf8d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=A4=92=20=E8=80=80=E5=B9=B3?= Date: Thu, 7 Jul 2022 15:03:09 +0900 Subject: [PATCH 3/3] =?UTF-8?q?B099=20=E5=8F=B0=E9=A2=A8=E3=81=AE=E6=8E=A5?= =?UTF-8?q?=E8=BF=91=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ykoiso/src/B099_Typhoon.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ykoiso/src/B099_Typhoon.java b/ykoiso/src/B099_Typhoon.java index 9953d84..02b7c49 100644 --- a/ykoiso/src/B099_Typhoon.java +++ b/ykoiso/src/B099_Typhoon.java @@ -15,9 +15,9 @@ public class B099_Typhoon { } // 行けるかどうかの判定 // 初期値はtrue - List ListOfIsGo = new ArrayList<>(); + List listOfIsGo = new ArrayList<>(); for (int i = 0; i < MAP_SIZE; i++) { - ListOfIsGo.add(true); + listOfIsGo.add(true); } // 行ける道のリスト // 出力用 @@ -31,32 +31,32 @@ public class B099_Typhoon { } // 行ける道の判定 - calcAbleLoad(ListOfIsGo, Map, MAP_SIZE, MAX_PRE_AMOUNT); + calcAbleLoad(listOfIsGo, Map, MAP_SIZE, MAX_PRE_AMOUNT); // 行ける道のリストの作成 - makeAbleList(ableLoad, ListOfIsGo, MAP_SIZE); + makeAbleList(ableLoad, listOfIsGo, MAP_SIZE); // 答えの表示 showAbleLoad(ableLoad); scan.close(); } // 行ける道の判定 - public static void calcAbleLoad(List ListOfIsGo, final List> Map, + public static void calcAbleLoad(List listOfIsGo, final List> Map, final int MAP_SIZE, final int MAX_PRE_AMOUNT) { for (int loadBlock = 0; loadBlock < MAP_SIZE; loadBlock++) { for (int loadNum = 0; loadNum < MAP_SIZE; loadNum++) { if (Map.get(loadNum).get(loadBlock) >= MAX_PRE_AMOUNT) { - ListOfIsGo.set(loadNum, false); + listOfIsGo.set(loadNum, false); } } } } // 行ける道のリストの生成 - public static void makeAbleList(List ableLoad, final List ListOfIsGo, + public static void makeAbleList(List ableLoad, final List listOfIsGo, final int MAP_SIZE) { for (int i = 0; i < MAP_SIZE; i++) { - if (ListOfIsGo.contains(true)) { - if (ListOfIsGo.get(i) == true) { + if (listOfIsGo.contains(true)) { + if (listOfIsGo.get(i) == true) { ableLoad.add(i + 1); } } -- GitLab