관리 메뉴

fatalite

Sales by Match 본문

코딩 인터뷰/C++

Sales by Match

fataliteforu 2023. 2. 4. 10:41

if문.. 줄여야하는데

/*
 * Complete the 'sockMerchant' function below.
 *
 * The function is expected to return an INTEGER.
 * The function accepts following parameters:
 *  1. INTEGER n
 *  2. INTEGER_ARRAY ar
 */

int sockMerchant(int n, vector<int> ar) {
    int cnt = 0;
    for(int i = 0; i < ar.size(); i++){
        if(ar[i] != 0){
            for(int k = 0; k < ar.size(); k++){
                if(i != k && ar[k] != 0){
                    if(ar[i] == ar[k]){
                        cnt++;
                        cout << ar[i] << " " << ar[k] << endl;
                        ar[i] = 0;
                        ar[k] = 0;
                    }
                }
            }
        }
    }
    return cnt;
}

'코딩 인터뷰 > C++' 카테고리의 다른 글

거짓말 - 백준 1043  (0) 2023.02.06
RGB 거리 - 백준 1149  (0) 2023.02.05
(파이썬 풀이) XOR String 3  (0) 2023.02.03
Subarray Division 2  (0) 2023.02.03
Permuting Two Arrays  (0) 2023.01.26