From 38e028032fdd09fa38f11e49d13e1af3e261d41a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=96=A2=20=E5=A4=A7=E8=BC=9D?= Date: Thu, 29 Jun 2023 15:10:35 +0900 Subject: [PATCH 1/4] =?UTF-8?q?paiza=E3=81=AEC117=E3=81=AE=E5=9B=9E?= =?UTF-8?q?=E7=AD=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dseki/paiza/src/C117.java | 110 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 dseki/paiza/src/C117.java diff --git a/dseki/paiza/src/C117.java b/dseki/paiza/src/C117.java new file mode 100644 index 0000000..a9997b3 --- /dev/null +++ b/dseki/paiza/src/C117.java @@ -0,0 +1,110 @@ +import java.util.ArrayList; +import java.util.Scanner; +/** + * 大量出店. + */ + +public class C117 { + /** + * メインメソッド. + */ + public static void main(final String[] args) { + final Scanner sc = new Scanner(System.in); + final int numberOfStores = sc.nextInt(); // 店舗数 + final int businessMonth = sc.nextInt(); // 営業する月数 + final int constructionCost = sc.nextInt(); // 1店舗あたりの建設費用 + final int laborCost = sc.nextInt(); // 1店舗当たりの人件費 + final int cupOfProfit = sc.nextInt(); // ラーメン1杯あたりの利益 + final ArrayList numberOfSalesList = new ArrayList(); + for (int i = 0; i < numberOfStores; i++) { + final int numberOfSales = sc.nextInt(); // その店舗が何杯ラーメンを売ったか + numberOfSalesList.add(numberOfSales); // 売った杯数をリストに追加 + } + + System.out.println(closeStore(numberOfStores, + cupOfProfit, + numberOfSalesList, + constructionCost, + laborCost, + businessMonth)); + sc.close(); + } + + // 店舗ごとの人件費を計算するメソッド + private static ArrayList laborCost(final int numberOfStores, + final int laborCost, + final int businessMonth) { + final ArrayList laborCostList = new ArrayList(); // 店舗ごとの人件費リスト + int storeLaborCost; // その店舗の人件費 + + // 店舗ごとの人件費リストに店舗の人件費を順番に格納する + for (int i = 0; i < numberOfStores; i++) { + storeLaborCost = laborCost * businessMonth; + laborCostList.add(storeLaborCost); + } + return laborCostList; + } + + // 店舗ごとのラーメンによる利益を出すメソッド + private static ArrayList proceed(final int numberOfStores, + final int cupOfProfit, + final ArrayList numberOfSalesList) { + final ArrayList ramenProfitList = new ArrayList(); // 店舗ごとのラーメンによる利益リスト + int storeProfit; // 店舗のラーメンによる利益 + + // 店舗ごとの利益を利益リストに格納する + for (int i = 0; i < numberOfStores; i++) { + storeProfit = cupOfProfit * numberOfSalesList.get(i); + ramenProfitList.add(storeProfit); + } + return ramenProfitList; + } + + // 店舗ごとの利益を計算するメソッド + private static ArrayList profit(final int numberOfStores, + final int cupOfProfit, + final ArrayList numberOfSalesList, + final int constructionCost, + final int laborCost, + final int businessMonth) { + final ArrayList profitList = new ArrayList(); // 店舗の利益リスト + int profit; // 店舗の利益 + + // 店舗の利益を利益リストに格納する + for (int i = 0; i < numberOfStores; i++) { + profit = proceed( + numberOfStores, + cupOfProfit, + numberOfSalesList).get(i) - constructionCost - laborCost(numberOfStores, + laborCost, + businessMonth).get(i); + profitList.add(profit); + } + return profitList; + } + + // 閉める店舗数を返すメソッド + private static int closeStore(final int numberOfStores, + final int cupOfProfit, + final ArrayList numberOfSalesList, + final int constructionCost, + final int laborCost, + final int businessMonth) { + final ArrayList closeList = new ArrayList(); // 閉める店舗の利益リスト + final ArrayList profitList = profit(numberOfStores, + cupOfProfit, + numberOfSalesList, + constructionCost, + laborCost, + businessMonth); + + // 店舗数分繰り返す + for (int i = 0; i < numberOfStores; i++) { + // 利益が0未満(赤字)なら閉店リストに格納する + if (profitList.get(i) < 0) { + closeList.add(profitList.get(i)); + } + } + return closeList.size(); // 閉店する店舗数を返す + } +} -- GitLab From 21b223e45de4dc6e419f7a74de1d326d7177b8a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=96=A2=20=E5=A4=A7=E8=BC=9D?= Date: Fri, 30 Jun 2023 10:44:24 +0900 Subject: [PATCH 2/4] =?UTF-8?q?paiza=20C117=20=E4=BF=AE=E6=AD=A3=E3=83=95?= =?UTF-8?q?=E3=82=A1=E3=82=A4=E3=83=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dseki/paiza/src/C117.java | 155 +++++++++++++++++++------------------- 1 file changed, 78 insertions(+), 77 deletions(-) diff --git a/dseki/paiza/src/C117.java b/dseki/paiza/src/C117.java index a9997b3..c0459e1 100644 --- a/dseki/paiza/src/C117.java +++ b/dseki/paiza/src/C117.java @@ -1,57 +1,91 @@ import java.util.ArrayList; import java.util.Scanner; + /** * 大量出店. */ - public class C117 { /** * メインメソッド. */ public static void main(final String[] args) { final Scanner sc = new Scanner(System.in); - final int numberOfStores = sc.nextInt(); // 店舗数 - final int businessMonth = sc.nextInt(); // 営業する月数 - final int constructionCost = sc.nextInt(); // 1店舗あたりの建設費用 - final int laborCost = sc.nextInt(); // 1店舗当たりの人件費 - final int cupOfProfit = sc.nextInt(); // ラーメン1杯あたりの利益 + final int numberOfStores = sc.nextInt(); // 店舗数 + final int businessMonth = sc.nextInt(); // 営業する月数 + final int constructionCost = sc.nextInt(); // 1店舗あたりの建設費用 + final int laborCost = sc.nextInt(); // 1店舗当たりの人件費 + final int cupOfProfit = sc.nextInt(); // ラーメン1杯あたりの利益 final ArrayList numberOfSalesList = new ArrayList(); for (int i = 0; i < numberOfStores; i++) { - final int numberOfSales = sc.nextInt(); // その店舗が何杯ラーメンを売ったか - numberOfSalesList.add(numberOfSales); // 売った杯数をリストに追加 + final int numberOfSales = sc.nextInt(); // その店舗が何杯ラーメンを売ったか + numberOfSalesList.add(numberOfSales); // 売った杯数をリストに追加 } - - System.out.println(closeStore(numberOfStores, - cupOfProfit, - numberOfSalesList, - constructionCost, - laborCost, - businessMonth)); + + System.out.println(closeStoreCount(numberOfStores, + cupOfProfit, + numberOfSalesList, + constructionCost, + laborCost, + businessMonth)); sc.close(); } + + // 閉める店舗数を返すメソッド + private static int closeStoreCount(final int numberOfStores, + final int cupOfProfit, + final ArrayList numberOfSalesList, + final int constructionCost, + final int laborCost, + final int businessMonth) { + final ArrayList closeCountList = new ArrayList(); // 閉める店舗の利益リスト + final ArrayList profitList = calculateProfit(numberOfStores, + cupOfProfit, + numberOfSalesList, + constructionCost, + laborCost, + businessMonth); + + // 店舗数分繰り返す + for (int i = 0; i < numberOfStores; i++) { + // 利益が0未満(赤字)なら閉店リストに格納する + if (profitList.get(i) < 0) { + closeCountList.add(profitList.get(i)); + } + } + return closeCountList.size(); // 閉店する店舗数を返す + } - // 店舗ごとの人件費を計算するメソッド - private static ArrayList laborCost(final int numberOfStores, - final int laborCost, - final int businessMonth) { - final ArrayList laborCostList = new ArrayList(); // 店舗ごとの人件費リスト - int storeLaborCost; // その店舗の人件費 - - // 店舗ごとの人件費リストに店舗の人件費を順番に格納する + //店舗ごとの利益を計算するメソッド + private static ArrayList calculateProfit(final int numberOfStores, + final int cupOfProfit, + final ArrayList numberOfSalesList, + final int constructionCost, + final int laborCost, + final int businessMonth) { + final ArrayList profitList = new ArrayList(); // 店舗の利益リスト + int profit; // 店舗の利益 + final ArrayList profitFromRamen = calculateProfitFromRamen(numberOfStores, + cupOfProfit, + numberOfSalesList); + final ArrayList calculateLaborCost = calculateLaborCost(numberOfStores, + laborCost, + businessMonth); + + // 店舗の利益を利益リストに格納する for (int i = 0; i < numberOfStores; i++) { - storeLaborCost = laborCost * businessMonth; - laborCostList.add(storeLaborCost); + profit = profitFromRamen.get(i) - constructionCost - calculateLaborCost.get(i); + profitList.add(profit); } - return laborCostList; + return profitList; } - // 店舗ごとのラーメンによる利益を出すメソッド - private static ArrayList proceed(final int numberOfStores, - final int cupOfProfit, - final ArrayList numberOfSalesList) { - final ArrayList ramenProfitList = new ArrayList(); // 店舗ごとのラーメンによる利益リスト - int storeProfit; // 店舗のラーメンによる利益 - + //店舗ごとのラーメンによる利益を出すメソッド + private static ArrayList calculateProfitFromRamen(final int numberOfStores, + final int cupOfProfit, + final ArrayList numberOfSalesList) { + final ArrayList ramenProfitList = new ArrayList(); // 店舗ごとのラーメンによる利益リスト + int storeProfit; // 店舗のラーメンによる利益 + // 店舗ごとの利益を利益リストに格納する for (int i = 0; i < numberOfStores; i++) { storeProfit = cupOfProfit * numberOfSalesList.get(i); @@ -60,51 +94,18 @@ public class C117 { return ramenProfitList; } - // 店舗ごとの利益を計算するメソッド - private static ArrayList profit(final int numberOfStores, - final int cupOfProfit, - final ArrayList numberOfSalesList, - final int constructionCost, - final int laborCost, - final int businessMonth) { - final ArrayList profitList = new ArrayList(); // 店舗の利益リスト - int profit; // 店舗の利益 - - // 店舗の利益を利益リストに格納する + // 店舗ごとの人件費を計算するメソッド + private static ArrayList calculateLaborCost(final int numberOfStores, + final int laborCost, + final int businessMonth) { + final ArrayList laborCostPerStoreList = new ArrayList(); // 店舗ごとの人件費リスト + int storeLaborCost; // その店舗の人件費 + + // 店舗ごとの人件費リストに店舗の人件費を順番に格納する for (int i = 0; i < numberOfStores; i++) { - profit = proceed( - numberOfStores, - cupOfProfit, - numberOfSalesList).get(i) - constructionCost - laborCost(numberOfStores, - laborCost, - businessMonth).get(i); - profitList.add(profit); + storeLaborCost = laborCost * businessMonth; + laborCostPerStoreList.add(storeLaborCost); } - return profitList; + return laborCostPerStoreList; } - - // 閉める店舗数を返すメソッド - private static int closeStore(final int numberOfStores, - final int cupOfProfit, - final ArrayList numberOfSalesList, - final int constructionCost, - final int laborCost, - final int businessMonth) { - final ArrayList closeList = new ArrayList(); // 閉める店舗の利益リスト - final ArrayList profitList = profit(numberOfStores, - cupOfProfit, - numberOfSalesList, - constructionCost, - laborCost, - businessMonth); - - // 店舗数分繰り返す - for (int i = 0; i < numberOfStores; i++) { - // 利益が0未満(赤字)なら閉店リストに格納する - if (profitList.get(i) < 0) { - closeList.add(profitList.get(i)); - } - } - return closeList.size(); // 閉店する店舗数を返す - } } -- GitLab From 0e85d0a05051ddddd2cc729a99e95a864992eff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=96=A2=20=E5=A4=A7=E8=BC=9D?= Date: Fri, 30 Jun 2023 11:51:10 +0900 Subject: [PATCH 3/4] =?UTF-8?q?paiza=20C117=20=E4=BF=AE=E6=AD=A3=E3=83=95?= =?UTF-8?q?=E3=82=A1=E3=82=A4=E3=83=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dseki/paiza/src/C117.java | 91 ++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 45 deletions(-) diff --git a/dseki/paiza/src/C117.java b/dseki/paiza/src/C117.java index c0459e1..bc89c1b 100644 --- a/dseki/paiza/src/C117.java +++ b/dseki/paiza/src/C117.java @@ -21,29 +21,29 @@ public class C117 { numberOfSalesList.add(numberOfSales); // 売った杯数をリストに追加 } - System.out.println(closeStoreCount(numberOfStores, - cupOfProfit, - numberOfSalesList, - constructionCost, - laborCost, - businessMonth)); + System.out.println(countStoreToClose(numberOfStores, + cupOfProfit, + numberOfSalesList, + constructionCost, + laborCost, + businessMonth)); sc.close(); } // 閉める店舗数を返すメソッド - private static int closeStoreCount(final int numberOfStores, - final int cupOfProfit, - final ArrayList numberOfSalesList, - final int constructionCost, - final int laborCost, - final int businessMonth) { + private static int countStoreToClose(final int numberOfStores, + final int cupOfProfit, + final ArrayList numberOfSalesList, + final int constructionCost, + final int laborCost, + final int businessMonth) { final ArrayList closeCountList = new ArrayList(); // 閉める店舗の利益リスト - final ArrayList profitList = calculateProfit(numberOfStores, - cupOfProfit, - numberOfSalesList, - constructionCost, - laborCost, - businessMonth); + final ArrayList profitList = calculateProfitPerStore(numberOfStores, + cupOfProfit, + numberOfSalesList, + constructionCost, + laborCost, + businessMonth); // 店舗数分繰り返す for (int i = 0; i < numberOfStores; i++) { @@ -54,56 +54,57 @@ public class C117 { } return closeCountList.size(); // 閉店する店舗数を返す } - - //店舗ごとの利益を計算するメソッド - private static ArrayList calculateProfit(final int numberOfStores, - final int cupOfProfit, - final ArrayList numberOfSalesList, - final int constructionCost, - final int laborCost, - final int businessMonth) { + + // 店舗ごとの利益を計算するメソッド + private static ArrayList calculateProfitPerStore(final int numberOfStores, + final int cupOfProfit, + final ArrayList numberOfSalesList, + final int constructionCost, + final int laborCost, + final int businessMonth) { final ArrayList profitList = new ArrayList(); // 店舗の利益リスト - int profit; // 店舗の利益 - final ArrayList profitFromRamen = calculateProfitFromRamen(numberOfStores, - cupOfProfit, - numberOfSalesList); - final ArrayList calculateLaborCost = calculateLaborCost(numberOfStores, - laborCost, - businessMonth); + final ArrayList profitFromRamenPerStore = calculateProfitFromRamenPerStore( + numberOfStores, + cupOfProfit, + numberOfSalesList); + final ArrayList laborCostPerStore = calculateLaborCostPerStore( + numberOfStores, + laborCost, + businessMonth); // 店舗の利益を利益リストに格納する for (int i = 0; i < numberOfStores; i++) { - profit = profitFromRamen.get(i) - constructionCost - calculateLaborCost.get(i); + final int profit = profitFromRamenPerStore.get(i) + - (constructionCost + laborCostPerStore.get(i)); profitList.add(profit); } return profitList; } - - //店舗ごとのラーメンによる利益を出すメソッド - private static ArrayList calculateProfitFromRamen(final int numberOfStores, + + // 店舗ごとのラーメンによる利益を出すメソッド + private static ArrayList calculateProfitFromRamenPerStore( + final int numberOfStores, final int cupOfProfit, final ArrayList numberOfSalesList) { final ArrayList ramenProfitList = new ArrayList(); // 店舗ごとのラーメンによる利益リスト - int storeProfit; // 店舗のラーメンによる利益 // 店舗ごとの利益を利益リストに格納する for (int i = 0; i < numberOfStores; i++) { - storeProfit = cupOfProfit * numberOfSalesList.get(i); + final int storeProfit = cupOfProfit * numberOfSalesList.get(i); // その店舗のラーメンによる利益を代入 ramenProfitList.add(storeProfit); } return ramenProfitList; } - + // 店舗ごとの人件費を計算するメソッド - private static ArrayList calculateLaborCost(final int numberOfStores, - final int laborCost, - final int businessMonth) { + private static ArrayList calculateLaborCostPerStore(final int numberOfStores, + final int laborCost, + final int businessMonth) { final ArrayList laborCostPerStoreList = new ArrayList(); // 店舗ごとの人件費リスト - int storeLaborCost; // その店舗の人件費 // 店舗ごとの人件費リストに店舗の人件費を順番に格納する for (int i = 0; i < numberOfStores; i++) { - storeLaborCost = laborCost * businessMonth; + final int storeLaborCost = laborCost * businessMonth; // その店舗の人件費を代入する laborCostPerStoreList.add(storeLaborCost); } return laborCostPerStoreList; -- GitLab From f630a9ad4190bdd07552881a004a6409d8ac7870 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=96=A2=20=E5=A4=A7=E8=BC=9D?= Date: Fri, 30 Jun 2023 13:46:59 +0900 Subject: [PATCH 4/4] =?UTF-8?q?=E3=82=B3=E3=83=9F=E3=83=83=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dseki/paiza/src/C117.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dseki/paiza/src/C117.java b/dseki/paiza/src/C117.java index bc89c1b..af89e0c 100644 --- a/dseki/paiza/src/C117.java +++ b/dseki/paiza/src/C117.java @@ -109,4 +109,4 @@ public class C117 { } return laborCostPerStoreList; } -} +} \ No newline at end of file -- GitLab