※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 26552번 문제인 Zero이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/26552
26552번: Zero
You’re writing the positive integers in increasing order starting from one. But you’ve never learned the digit zero, and thus omit any number that contains a zero in any position. The first ten integers you write are: 1, 2, 3, 4, 5, 6, 7, 8, 9, and 11.
www.acmicpc.net
각 주어진 수보다 큰 수중 자릿수에 0이 없는 가장 작은 수를 찾는 문제이다.
각 수에 1을 더한 뒤 그 수가 자릿수에 0이 없는 수가 될 때까지 1을 계속 더해나가는 것으로 문제를 해결할 수 있다.
이는 while문과 해당 수의 자릿수에 0이 존재하는지를 확인하는 함수 하나를 작성하는 것으로 간단히 구현할 수 있다.
아래는 제출한 소스코드이다.
#include <iostream>
using namespace std;
int T;
int cur;
bool zerochk(int x) {
while (x) {
if (x % 10 == 0) return 1;
x /= 10;
}
return 0;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> T;
while (T--) {
cin >> cur; cur++;
while (zerochk(cur)) cur++;
cout << cur << '\n';
}
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 26533 // C++] Tractor Path (0) | 2022.12.21 |
---|---|
[BOJ 26564 // C++] Poker Hand (0) | 2022.12.21 |
[BOJ 26535 // C++] Chicken Pen (0) | 2022.12.21 |
[BOJ 10187 // C++] Golden (0) | 2022.12.21 |
[BOJ 26502 // C++] Decoder (0) | 2022.12.21 |