Title Address: http://acm.nyist.net/JudgeOnline/problem.php?pid=39 Description
Please determine if a number is a narcissus number.
Wherein Narcissus number defines the individual bits of the cubic and equals to its own three-digit number.
Input
There are multiple sets of test data, each set of test data to contain an integer n (100<=n<1000)
Enter 0 to indicate the end of the program input.
Output
If n is the number of daffodils, output yes
Otherwise output no
Sample input
153
154
0
Sample output
Yes
No code: #include <stdio.h>
int main ()
{
int a = 0;
int b = 0;
int c = 0;
Do
{
int readnum = 0;
scanf ("%d", &readnum);
GetChar ();
if (Readnum < | | readnum >= 1000)
{
Break
}
int tmp = Readnum;
A = tmp/100;
TMP = tmp%100;
b = TMP/10;
c = tmp%10;
if (a*a*a + b*b*b + c*c*c = = Readnum)
{
printf ("yes\n");
}
Else
{
printf ("no\n");
}
}while (1);
return 0;
} Recommended Good code:
#include <iostream>
using namespace Std;
int main ()
{
int A;
while (1)
{
cin>>a;
if (a==0) break;
cout<< ((a==153| | a==370| | a==371| | a==407)? " Yes ":" No ") <<endl;
}
} Although ... But... Lazy thinking is still needed, after all, the programmer should be the pursuit of simplicity, not advanced, but as an introduction to the practiced hand problem, consider how to break down an integer number of individual digits, or need to master.
11-Language Introduction -11-narcissus number