From 57a194eb528950650a40de679473b52f68f5a79e Mon Sep 17 00:00:00 2001 From: htabuchi Date: Mon, 30 Jun 2025 16:27:27 +0900 Subject: [PATCH 1/2] =?UTF-8?q?paiza=E3=81=AE=E5=95=8F=E9=A1=8CC166?= =?UTF-8?q?=E3=81=AE=E5=9B=9E=E7=AD=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htabuchi/src/C166_htabuchi.java | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 htabuchi/src/C166_htabuchi.java diff --git a/htabuchi/src/C166_htabuchi.java b/htabuchi/src/C166_htabuchi.java new file mode 100644 index 0000000..2c3351e --- /dev/null +++ b/htabuchi/src/C166_htabuchi.java @@ -0,0 +1,37 @@ +package PaizaTraining.src; + +import java.util.Scanner; + +public class C166_htabuchi { + public static int countCoin(int money) { + // それぞれのコインの値から枚数を算出 + int[] coin_data = { + 500, 100, 50, 10, 5, 1 + }; + int sum_coin = 0; + + for (int coin : coin_data) { + sum_coin += coinNum(money, coin); + money = moneyRemainder(money, coin); + } + return sum_coin; + } + + public static int coinNum(int sum, int coin) { + return sum / coin; + } + + public static int moneyRemainder(int sum, int coin) { + return sum % coin; + } + + public static void main(String[] args) { + // 金額から必要なコインの枚数の最小値を表示 + Scanner sc = new Scanner(System.in); + int money = sc.nextInt(); + + System.out.println(countCoin(money)); + + sc.close(); + } +} -- GitLab From 07406ac612be41935a65fa0955f237ffb72e5ebd Mon Sep 17 00:00:00 2001 From: htabuchi Date: Tue, 1 Jul 2025 14:21:19 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E2=80=9Cpainza=E3=81=AE=E5=95=8F=E9=A1=8CC?= =?UTF-8?q?166=E3=81=AE=E8=A7=A3=E7=AD=94=E3=82=92=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .classpath | 7 +++++++ .gitignore | 1 + .project | 17 ++++++++++++++++ htabuchi/.classpath | 5 +++++ htabuchi/.project | 17 ++++++++++++++++ htabuchi/src/C166_htabuchi.java | 35 ++++++++++++++++++++------------- 6 files changed, 68 insertions(+), 14 deletions(-) create mode 100644 .classpath create mode 100644 .gitignore create mode 100644 .project create mode 100644 htabuchi/.classpath create mode 100644 htabuchi/.project diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..35d3fa4 --- /dev/null +++ b/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/.project b/.project new file mode 100644 index 0000000..9d211bd --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + paiza + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/htabuchi/.classpath b/htabuchi/.classpath new file mode 100644 index 0000000..ac37fb2 --- /dev/null +++ b/htabuchi/.classpath @@ -0,0 +1,5 @@ + + + + + diff --git a/htabuchi/.project b/htabuchi/.project new file mode 100644 index 0000000..c36ea14 --- /dev/null +++ b/htabuchi/.project @@ -0,0 +1,17 @@ + + + htabuchi + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/htabuchi/src/C166_htabuchi.java b/htabuchi/src/C166_htabuchi.java index 2c3351e..ccec5a6 100644 --- a/htabuchi/src/C166_htabuchi.java +++ b/htabuchi/src/C166_htabuchi.java @@ -1,36 +1,43 @@ -package PaizaTraining.src; +/** + * Paiza問題C166:ちょうどの支払い
+ * 修正2025/07/01 13:40 + * + * @author 田渕日奈子 + * @version 1.1 + */ import java.util.Scanner; public class C166_htabuchi { - public static int countCoin(int money) { - // それぞれのコインの値から枚数を算出 - int[] coin_data = { + public static int countCoin(int price) { + /** それぞれのコインの値から枚数を算出 */ + + int[] coinData = {/** コインの種類 */ 500, 100, 50, 10, 5, 1 }; - int sum_coin = 0; + int sumCoin = 0; - for (int coin : coin_data) { - sum_coin += coinNum(money, coin); - money = moneyRemainder(money, coin); + for (int coin : coinData) { + sumCoin += countCoinNum(price, coin); + price = calcRestOfPrice(price, coin); } - return sum_coin; + return sumCoin; } - public static int coinNum(int sum, int coin) { + public static int countCoinNum(int sum, int coin) { return sum / coin; } - public static int moneyRemainder(int sum, int coin) { + public static int calcRestOfPrice(int sum, int coin) { return sum % coin; } public static void main(String[] args) { - // 金額から必要なコインの枚数の最小値を表示 + /** 金額から必要なコインの枚数の最小値を表示 */ Scanner sc = new Scanner(System.in); - int money = sc.nextInt(); + int price = sc.nextInt(); - System.out.println(countCoin(money)); + System.out.println(countCoin(price)); sc.close(); } -- GitLab