알고리즘

[알고리즘] 백준 2863 - 이게 분수? (C++)

blueberrysoda 2024. 11. 20. 23:57

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

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

double Arr[5];
double Ans[4];

int main(){    
    for(int i=1; i<=4; i++){
        cin >> Arr[i];
    }
    
    Ans[0] = Arr[1] / Arr[3] + Arr[2] / Arr[4];
    Ans[1] = Arr[3] / Arr[4] + Arr[1] / Arr[2];
    Ans[2] = Arr[4] / Arr[2] + Arr[3] / Arr[1];
    Ans[3] = Arr[2] / Arr[1] + Arr[4] / Arr[3];

    double r = 0;
    int m = 10;

    for(int i=0; i<4; i++){
        if(r < Ans[i]){
            r = Ans[i];
        }
    }

    for(int i=0; i<4; i++){
        if(r == Ans[i]){
            m = min(m, i);
        }
    }
    
    cout << m << "\n";
    return 0;
}