diff --git a/dseki/paiza/src/C117.java b/dseki/paiza/src/C117.java new file mode 100644 index 0000000000000000000000000000000000000000..af89e0c510b33bde2fd65dc802dcb57d330c0891 --- /dev/null +++ b/dseki/paiza/src/C117.java @@ -0,0 +1,112 @@ +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(countStoreToClose(numberOfStores, + cupOfProfit, + numberOfSalesList, + constructionCost, + laborCost, + businessMonth)); + sc.close(); + } + + // 閉める店舗数を返すメソッド + 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 = calculateProfitPerStore(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 calculateProfitPerStore(final int numberOfStores, + final int cupOfProfit, + final ArrayList numberOfSalesList, + final int constructionCost, + final int laborCost, + final int businessMonth) { + final ArrayList profitList = new ArrayList(); // 店舗の利益リスト + final ArrayList profitFromRamenPerStore = calculateProfitFromRamenPerStore( + numberOfStores, + cupOfProfit, + numberOfSalesList); + final ArrayList laborCostPerStore = calculateLaborCostPerStore( + numberOfStores, + laborCost, + businessMonth); + + // 店舗の利益を利益リストに格納する + for (int i = 0; i < numberOfStores; i++) { + final int profit = profitFromRamenPerStore.get(i) + - (constructionCost + laborCostPerStore.get(i)); + profitList.add(profit); + } + return profitList; + } + + // 店舗ごとのラーメンによる利益を出すメソッド + private static ArrayList calculateProfitFromRamenPerStore( + final int numberOfStores, + final int cupOfProfit, + final ArrayList numberOfSalesList) { + final ArrayList ramenProfitList = new ArrayList(); // 店舗ごとのラーメンによる利益リスト + + // 店舗ごとの利益を利益リストに格納する + for (int i = 0; i < numberOfStores; i++) { + final int storeProfit = cupOfProfit * numberOfSalesList.get(i); // その店舗のラーメンによる利益を代入 + ramenProfitList.add(storeProfit); + } + return ramenProfitList; + } + + // 店舗ごとの人件費を計算するメソッド + private static ArrayList calculateLaborCostPerStore(final int numberOfStores, + final int laborCost, + final int businessMonth) { + final ArrayList laborCostPerStoreList = new ArrayList(); // 店舗ごとの人件費リスト + + // 店舗ごとの人件費リストに店舗の人件費を順番に格納する + for (int i = 0; i < numberOfStores; i++) { + final int storeLaborCost = laborCost * businessMonth; // その店舗の人件費を代入する + laborCostPerStoreList.add(storeLaborCost); + } + return laborCostPerStoreList; + } +} \ No newline at end of file