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);
}
}
댓글