728x90
반응형
27494번: 2023년은 검은 토끼의 해
문제
https://www.acmicpc.net/problem/27494
27494번: 2023년은 검은 토끼의 해
흑묘 복권의 티켓 수 $N$이 주어진다. $(1 \leq N \leq 10\,000\,000)$
www.acmicpc.net
풀이
2023부터 N까지 차례대로 문자열로 바꾸어 어느 한 부분에 차례대로 2, 0, 2, 3이 존재하는지 확인하면 되는 문제다.
코드
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, ans = 0;
cin >> n;
for (int i = 2023; i <= n; i++) {
string num = to_string(i);
if (num.find('2', 0) != string::npos) {
int idx = num.find('2', 0);
if (num.find('0', idx) != string::npos) {
idx = num.find('0', idx);
if (num.find('2', idx) != string::npos) {
idx = num.find('2', idx);
if (num.find('3', idx) != string::npos)
ans++;
}
}
}
}
cout << ans << '\n';
return 0;
}
728x90
반응형
'Problem Solving > BOJ' 카테고리의 다른 글
[백준 / BOJ] C++ 27496 발머의 피크 이론 (0) | 2023.02.20 |
---|---|
[백준 / BOJ] C++ 27495 만다라트 만들기 (0) | 2023.02.20 |
[백준 / BOJ] C++ 4485 녹색 옷 입은 애가 젤다지? (0) | 2023.02.20 |
[백준 / BOJ] C++ 18223 민준이와 마산 그리고 건우 (0) | 2023.02.20 |
[백준 / BOJ] C++ 17396 백도어 (0) | 2023.02.20 |