PS

[C++] 초콜릿과 11과 팰린드롬 (백준 31460번)

jungh150c 2025. 3. 24. 16:27

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

 

#include <iostream>
#include <vector>
using namespace std;

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

    int t;
    cin >> t;

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

        if (n == 1) {
            cout << 0 << '\n';
        } else {
            cout << 1;
            for (int i = 0; i < n - 2; i++) cout << 2;
            cout << 1 << '\n';
        }
    }
}

0

11

121

1221

12221

122221

...

이렇게 규칙만 찾으면 쉽게 풀 수 있는 문제. 0도 11의 배수임에 주의하자. (AC)