웅재의 코딩세상

[프로그래머스] 주사위 게임 3 본문

코딩테스트/프로그래머스 - LV 0

[프로그래머스] 주사위 게임 3

웅드 2024. 1. 30. 15:39

 

 

  • 풀이
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int solution(int a, int b, int c, int d) {
    vector<int> v={a,b,c,d};
    sort(v.begin(), v.end());
    if(v[0] == v[3]) return 1111 * v[0];
    else if(v[0] == v[2]) return (10*v[0] + v[3]) * (10*v[0] + v[3]);
    else if(v[1] == v[3]) return (10*v[1] + v[0]) * (10*v[1] + v[0]);
    else if(v[0] == v[1]){
        if(v[2]==v[3]) return (v[0]+v[2]) * (v[2]-v[0]);
        else return v[2]*v[3];
    }
    else if(v[2]==v[3]) return v[0] * v[1];
    else if(v[1] == v[2]) return v[0]*v[3];
    else return v[0];
}
반응형