๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm ๐Ÿง‘๐Ÿป‍๐Ÿ’ป/๋ฐฑ์ค€(BOJ)

[๋ฐฑ์ค€,c++] 11866๋ฒˆ - ์š”์„ธํ‘ธ์Šค ๋ฌธ์ œ0

by dkswnkk 2021. 11. 2.
 

11866๋ฒˆ: ์š”์„ธํ‘ธ์Šค ๋ฌธ์ œ 0

์ฒซ์งธ ์ค„์— N๊ณผ K๊ฐ€ ๋นˆ ์นธ์„ ์‚ฌ์ด์— ๋‘๊ณ  ์ˆœ์„œ๋Œ€๋กœ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ K ≤ N ≤ 1,000)

www.acmicpc.net

 

#include <iostream>
#include <queue>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int N, K; cin >> N>>K;
    queue<int>q;

    for (int i = 1; i <= N; i++) {
        q.push(i);
    }
    cout << "<";
    while (!q.empty()) {
        int cnt = 1;
        while (true) {
            if (cnt == K) {
                cout << q.front();
                q.pop();
                if (!q.empty()) cout << ", ";
                break;
            }
            int temp = q.front();
            q.pop();
            q.push(temp);
            cnt++;
        }

    }
    cout << ">";
}

๋Œ“๊ธ€