diff --git a/kurisu/src/C116.java b/kurisu/src/C116.java new file mode 100644 index 0000000000000000000000000000000000000000..2bfd2a2c1fd1da0a80fd1fa96144f6cd3397dc39 --- /dev/null +++ b/kurisu/src/C116.java @@ -0,0 +1,49 @@ +import java.util.Scanner; + +class Check_stick { + private int consective_mark = 0; + private boolean wrong_flag = false; + + Check_stick() {} + + //外れ棒の連続回数が指定回数より上回ればフラグをtrue、それ以外はfalseを返す + boolean inspectionStick(int stick, int wrong_rod, Scanner sc) { + for(int i = 0; i < stick; i++){ + int stick_result = sc.nextInt(); + + if(consective_mark < wrong_rod) { + if(stick_result == 0){//外れが連続すればカウントしていく + consective_mark++; + }else if(stick_result != 0) {//連続が途切れた場合カウントを最初からやり直す + consective_mark = 0; + } + } + if(consective_mark >= wrong_rod) { + wrong_flag = true; + } + } + return wrong_flag; + } +} + +class Show_result { + Show_result(boolean inspect_result) { + if(inspect_result == true) { + System.out.println("NG"); + }else { + System.out.println("OK"); + } + } +} + +public class C116 { + public static void main(String[] args ) throws Exception { + Scanner sc = new Scanner(System.in); + final int ice_stick = sc.nextInt(); + final int wrong_rod = sc.nextInt(); + Check_stick result_flag = new Check_stick(); + final boolean inspect_result = result_flag.inspectionStick(ice_stick, wrong_rod, sc); + new Show_result(inspect_result); + sc.close(); + } +} \ No newline at end of file diff --git a/kurisu/src/C166_JustPay.java b/kurisu/src/C166_JustPay.java new file mode 100644 index 0000000000000000000000000000000000000000..1d8ac4ff6c70544c0f07f45a098ce2d9bc316e34 --- /dev/null +++ b/kurisu/src/C166_JustPay.java @@ -0,0 +1,52 @@ +import java.util.Scanner; + +enum Coin { + COIN_500(500), + COIN_100(100), + COIN_50(50), + COIN_10(10), + COIN_5(5), + COIN_1(1); + + private final int money; + + Coin(int money) { + this.money = money; + } + + public int getMoney() { + return money; + } +} + + +class CoinCounter { + private int totalcoin = 0; + + CoinCounter() {} + + final int countCoin(int remainingamount) { + for (Coin coin : Coin.values()) { + totalcoin += remainingamount / coin.getMoney(); + remainingamount %= coin.getMoney(); + } + return totalcoin; + } +} + + +public class C166_JustPay { + public static void main(String[] args) { + final Scanner sc = new Scanner(System.in); + final String line = sc.nextLine(); + + // String型をint型に変換 + final int money = Integer.parseInt(line); + + final CoinCounter coinCounter = new CoinCounter(); + + System.out.print(coinCounter.countCoin(money)); + + sc.close(); + } +}