11-Language Introduction -11-narcissus number

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.