본문 바로가기
개발/코딩

해커랭크(HackerRank) - Bon Appétit / C++

by lucidmaj7 2020. 6. 26.
728x90
반응형

문제 : 해커랭크  - Bon Appétit

https://www.hackerrank.com/challenges/bon-appetit/problem

 

Bon Appétit | HackerRank

Determine whether or not Brian overcharged Anna for their split bill.

www.hackerrank.com

난이도: Easy

언어 : C++

 

// Complete the bonAppetit function below.
void bonAppetit(vector<int> bill, int k, int b) {
    int annaToChargeSum = 0;
    int toRefund = 0;
    for(int i = 0 ;i<bill.size();i++)
    {
        if(i!=k)
            annaToChargeSum+=bill[i];
    }
    annaToChargeSum=annaToChargeSum/2;
    
   toRefund = b-annaToChargeSum ;
   toRefund == 0 ? 
        cout <<"Bon Appetit" <<endl:
        cout <<toRefund <<endl; 

}

728x90
반응형

댓글