알고리즘

[알고리즘] 백준 2997 - 네 번째 수 (C++)

blueberrysoda 2024. 11. 28. 23:33

[문제 링크] : https://www.acmicpc.net/problem/2997

#include <iostream>
#include <algorithm>
using namespace std;

int Arr[3];
int A, B;

int main(){
    for(int i=0; i<3; i++){
        cin >> Arr[i];
    }

    sort(Arr, Arr + 3);

    int A = Arr[1] - Arr[0];
    int B = Arr[2] - Arr[1];
    
    if(A > B){
        cout << Arr[0] + B << "\n";
    }
    else if(A == B){
        cout << Arr[2] + A << "\n";
    }
    else{
        cout << Arr[1] + A << "\n";
    }
    
    return 0;
}