The daffodil number is one of the famous interesting numbers in the mathematical world. A daffodil number is a three-digit number whose value is equal to the sum of cubes of each digit.
For example. 153 is a daffodil as 153 = 13 + 53 + 33.
Input
There are several test cases in the input, each case contains a three-digit number.
Output
One line for each case. if the given number is a daffodil number, then output "Yes", otherwise "No".
Sample Input
153
610
Sample Output
Yes
No
Author: LIU, Yaoting
Source: Zhejiang Provincial Programming Contest 2006, Preliminary
分析:
题意:
判断一个数是不是水仙花数。
水题。
ac代码:
#include <iostream>
#include<cstdio>
using namespace std;
int main()
{
int n;
int a,b,c;
while(scanf("%d",&n)!=EOF)
{
a=n/100;
b=(n-a*100)/10;
c=n%10;
if(n==a*a*a+b*b*b+c*c*c)
printf("Yes\n");
else printf("No\n");
}
return 0;
}
#include<cstdio>
using namespace std;
int main()
{
int n;
int a,b,c;
while(scanf("%d",&n)!=EOF)
{
a=n/100;
b=(n-a*100)/10;
c=n%10;
if(n==a*a*a+b*b*b+c*c*c)
printf("Yes\n");
else printf("No\n");
}
return 0;
}