1008. 水仙花数

题目描述

输入一个三位数n,判断是否为水仙花数,如果是则输出“YES”,不是则输出“NO”。水仙花数:是指一个3位数,它的每个位上的数字的3次幂之和等于它本身。(例如:1^3 + 5^3+ 3^3 = 153)

输入

输入一个三位数n。

输出

按照题目描述输出对应结果。

样例输入

153

样例输出

YES

数据范围限制

100<=n<=999
 1 #include<iostream>
 2 #include<cmath>
 3 using namespace std;
 4 int tot=0;
 5 int main()
 6 {
 7     int n;
 8     cin>>n;
 9     int j=n;
10     while(n!=0)
11     {
12         int a=n%10;
13         double p=(double)pow(a,3);
14         tot=tot+p;
15         n=n/10;
16     }
17     if(tot==j)
18     {
19         cout<<"YES";
20     }
21     else
22     {
23         cout<<"NO";
24     }
25     return 0;
26 }
原文地址:https://www.cnblogs.com/zwfymqz/p/6636629.html