백준 알고리즘(C/C++) - 4673번 셀프 넘버

#include <stdio.h>
int a(int n) {
	int s = n;
	while (1) {
		if (n == 0)break;
		s += n % 10;
		n /= 10;
	}
	return s;
}
int main() {
	int b[10001] = { 0, };
	for (int i = 1; i < 10001; i++) {
		int s = a(i);
		if (s < 10001)b[s] = 1;
		if (b[i] != 1)printf("%d\n", i);
	}
}
#include <iostream>
int a(int n) {
	int s = n;
	while (1) {
		if (n == 0)break;
		s += n % 10;
		n /= 10;
	}
	return s;
}
int main() {
	int b[10001] = { 0, };
	for (int i = 0; i < 10001; i++) {
		int s = a(i);
		if (s < 10001)b[s] = 1;
		if (b[i] != 1) std::cout << i << std::endl;
	}
}

댓글

Designed by JB FACTORY