Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- N과M
- 최소공배수
- 알고리즘
- BFS
- 에라토스테네스의 체
- priority_queue
- 이분탐색
- C++
- 정렬
- stoi
- 티스토리챌린지
- DP
- 우선순위큐
- 오블완
- Sort
- vector
- Set
- 깊이우선탐색
- 그래프
- 백준
- map
- 다이나믹프로그래밍
- 분할정복
- 배열
- 유클리드호제법
- 프로그래머스
- 백트래킹
- 문자열
- int
- DFS
Archives
- Today
- Total
안녕 세상아,
[백준/c++] 4673 셀프 넘버 본문
https://www.acmicpc.net/problem/4673
배열 만들어서 소거법해서 지우는 방법으로 풀면 된다.
자릿수 대로 나눠서 풀면 된다. out of bound가 되면 안되니까 10000이하일때만 값 바꾸게 한다.
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int arr[10001] = { 0 };
for (int i = 1; i <= 10000; i++) {
int k = i;
if (i < 10) {
k = i + i;
}
else if (i<100) {
int x = i % 10;
int y = i / 10;
k = i + x + y;
}
else if (i<1000) {
int y = i / 100;
int n = i % 100;
int z = n / 10;
int x = n % 10;
k = i + x + y + z;
}
else if (i <10000) {
int x = i / 1000;
int n = i % 1000;
int y = n / 100;
n = n % 100;
int z = n / 10;
int q = n % 10;
k = i + x + y + z + q;
}
if (k <= 10000) {
arr[k] = 1;
}
}
for (int i = 1; i <= 10000; i++) {
if (arr[i] == 0) {
cout << i << '\n';
}
}
}
'백준' 카테고리의 다른 글
[백준/c++] 분수 찾기 (0) | 2025.01.02 |
---|---|
[백준/c++] 좌표 정렬하기 (1) | 2025.01.01 |
[백준/c++] 2941 크로아티아 알파벳 (0) | 2024.12.28 |
[백준/c++] 2751 수 정렬하기 2 (0) | 2024.12.27 |
[백준/c++] 1316 그룹 단어 체커 (0) | 2024.12.17 |