diff --git a/ykoiso/src/B099_Typhoon.java b/ykoiso/src/B099_Typhoon.java new file mode 100644 index 0000000000000000000000000000000000000000..02b7c496c44259021fb64129b24d0dfa9fb9933c --- /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 MAP_SIZE = scan.nextInt(); + final int MAX_PRE_AMOUNT = scan.nextInt(); + // マップ + List> Map = new ArrayList<>(); + for (int i = 0; i < MAP_SIZE; i++) { + Map.add(new ArrayList<>()); + } + // 行けるかどうかの判定 + // 初期値は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 < MAP_SIZE; i++) { + for (int loadNum = 0; loadNum < MAP_SIZE; loadNum++) { + Map.get(loadNum).add(scan.nextInt()); + } + } + + // 行ける道の判定 + calcAbleLoad(listOfIsGo, Map, MAP_SIZE, MAX_PRE_AMOUNT); + // 行ける道のリストの作成 + makeAbleList(ableLoad, listOfIsGo, MAP_SIZE); + // 答えの表示 + showAbleLoad(ableLoad); + scan.close(); + } + + // 行ける道の判定 + 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 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); + } + } + } + } + + // 答えの生成 + 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 0000000000000000000000000000000000000000..394479ac8567d3e28500884c4a95380c9d5e42b6 --- /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)); + } +}