#31019: 新手HAPPY解


jason096727@gmail.com (Jason Ho)

學校 : 高雄市苓雅區福東國民小學
編號 : 189939
來源 : [150.116.71.76]
最後登入時間 :
2023-07-15 21:32:51
a040. 阿姆斯壯數 | From: [150.116.71.227] | 發表日期 : 2022-07-04 20:42

#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    int n,m,p=0;
    cin >> n >> m;
    for (int i=n; i<=m; i++){
        int count=0,x=i;
        while (x!=0){
            x=x/10;
            count++;
        }
        int y=i,sum=0;
        for (int j=1; j<=count; j++){
            int z = y%10;
            sum += pow(z,count);
            y=y/10;
        }
        if (sum==i){
            cout << sum << " ";
            p=1;
        }
    }
    if (p==0){
        cout << "none" << endl;
    }
    return 0;
}

 
ZeroJudge Forum