[백준/C++] 5217 - 쌍의 합

orangesnail·2025년 8월 23일

백준

목록 보기
148/169

https://www.acmicpc.net/problem/5217


중복되지 않게 같은 쌍을 찾기 위해 i*2 < n일때까지 반복해준다...

#include <iostream>
using namespace std;

int main() {
    int t;
    cin >> t;

    while (t--) {
        int n;
        cin >> n;

        cout << "Pairs for " << n << ":";

        bool isFirst = true;
        for (int i = 1; i * 2 < n; ++i) {
            int j = n - i;

            if (isFirst) {
                cout << " ";
                isFirst = false;
            }
            else cout << ", ";

            cout << i << " " << j;
        }
        cout << "\n";
    }
    return 0;
}
profile
초보입니다. 피드백 환영합니다 😗

0개의 댓글