🖥️ CS/Baekjoon Algorithms

#4153번 직각삼각형 (c++)

한국의 메타몽 2020. 2. 24. 23:08
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    while(true)
    {
        int line[3] = {0};
        int max = 0;
        for(int i=0; i<3; i++)
        {
            cin >> line[i];
            if(max<=line[i])
                max = line[i];
        }
        
        if(line[0]==0&&line[1]==0&&line[2]==0)
        {
            return 0;
        }
        
        sort(line,line+3);
        
        if(pow(line[2],2)==(pow(line[0],2)+pow(line[1],2)))
            cout << "right" << "\n";
        else
            cout << "wrong" <<"\n";
        
    }
    
    return 0;
}

한가지 재밋던 점은, 배열에서 처음 sort를 써보았던 점. 

vector의 경우 sort(v.begin(), v.end())와 같은 형식으로 주로 사용하였으나,

배열은 sort(a,a+3) -> 즉, sort(배열의 이름, 배열의 초기 선언 사이즈)로 선언한다.