๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ“šAlgorithm ------------/๋ฐฑ์ค€

๋ฐฑ์ค€ 4673๋ฒˆ: ์…€ํ”„๋„˜๋ฒ„ (C++)

https://www.acmicpc.net/problem/4673

 

4673๋ฒˆ: ์…€ํ”„ ๋„˜๋ฒ„

์…€ํ”„ ๋„˜๋ฒ„๋Š” 1949๋…„ ์ธ๋„ ์ˆ˜ํ•™์ž D.R. Kaprekar๊ฐ€ ์ด๋ฆ„ ๋ถ™์˜€๋‹ค. ์–‘์˜ ์ •์ˆ˜ n์— ๋Œ€ํ•ด์„œ d(n)์„ n๊ณผ n์˜ ๊ฐ ์ž๋ฆฌ์ˆ˜๋ฅผ ๋”ํ•˜๋Š” ํ•จ์ˆ˜๋ผ๊ณ  ์ •์˜ํ•˜์ž. ์˜ˆ๋ฅผ ๋“ค์–ด, d(75) = 75+7+5 = 87์ด๋‹ค. ์–‘์˜ ์ •์ˆ˜ n์ด ์ฃผ์–ด์กŒ์„ ๋•Œ,

www.acmicpc.net

 

 

#include <iostream>
#include <string>

#define MAX_NUM 10000
using namespace std;

int selfNum(int num)
{
    int sum = num;
    int d = num;
    do{
        sum += d%10;
        d = d/10;
    }while(d!=0);

    return sum;
}

int main(void)
{
    int n = 1;
    bool selfChk[MAX_NUM+1] = {false};

    for( int i=1; i <= MAX_NUM; i++ )
    {
        int ret = selfNum(i);
        if( ret <= MAX_NUM )
            selfChk[ret] = true;
    }

    for( int i=1; i <= MAX_NUM; i++ )
    {
        if( !selfChk[i] )
            cout << i << endl;
    }

    return 0;
}

 

self number ๊ตฌํ•˜๋Š”๊ฑฐ๋ž‘ ๋ฐฐ์—ด์— ๊ฒฐ๊ณผ ์ €์žฅํ•˜๋Š”๊ฑฐ๋งŒ

ํ•  ์ˆ˜ ์žˆ์œผ๋ฉด ๊ธˆ๋ฐฉํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์€ ๋ฌธ์ œ๋‹ค

 

 


๊ธˆ์šœ์—๋Š” ์ง‘์ค‘์ด ์ง„์งœ ์•ˆ๋œ๋‹ค

๊ฐ„๋‹จํ•œ๊ฑด๋ฐ ๋ช‡๋ถ„์ด ๊ฑธ๋ฆฐ๊ฑฐ์ง•ใ…Žใ…Ž;