Notice
Recent Posts
Link
정화 코딩
[C++] 초콜릿과 11과 팰린드롬 (백준 31460번) 본문
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)
'PS' 카테고리의 다른 글
[C++] 사전 순 최대 공통 부분 수열 (0) | 2025.03.30 |
---|---|
[C++] △ (백준 27966번) (0) | 2025.03.26 |
[C++] 포항항 (백준 23817번) (0) | 2025.03.22 |
[C++] Σ (백준 13172번) (0) | 2025.03.22 |
[C++] 숨바꼭질 2 (백준 12851번) (0) | 2025.03.18 |
Comments