본문 바로가기
개발공간

C# Bill Division [HackerRank]

by -0o0- 2021. 9. 10.

C# BillDivision [HackerRank]

using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System;

class Result
{
    public static void bonAppetit(List<int> bill, int k, int b)
    {
        int annaPay = 0;
        
        for(int i=0; i<bill.Count; i++)
        {
            //애나가 먹은 인덱스 번호 제외하고 계산
            if(i != k)
            {
                annaPay += bill[i];
            }
        }
        //청구서 - 계산서 / 2
        annaPay = b-annaPay/2;
        
        //0원이면 BonAppetit, 아니면 annaPay 출력
        if(annaPay==0) Console.WriteLine("Bon Appetit");
        else Console.WriteLine(annaPay);
    }

}

class Solution
{
    public static void Main(string[] args)
    {
        string[] firstMultipleInput = Console.ReadLine().TrimEnd().Split(' ');

        int n = Convert.ToInt32(firstMultipleInput[0]);

        int k = Convert.ToInt32(firstMultipleInput[1]);

        List<int> bill = Console.ReadLine().TrimEnd().Split(' ').ToList().Select(billTemp => Convert.ToInt32(billTemp)).ToList();

        int b = Convert.ToInt32(Console.ReadLine().Trim());

        Result.bonAppetit(bill, k, b);
    }
}

'개발공간' 카테고리의 다른 글

C# Drawing Book [HackerRank]  (0) 2021.09.11
C# Sales by Match [HackerRank]  (0) 2021.09.10
C# Migratory Birds [HackerRank]  (0) 2021.09.09
C# Divisible Sum Pairs [HackerRank]  (0) 2021.09.09
C# Subarray Division [HackerRank]  (0) 2021.09.09

댓글