# 0067-Number of daffodils

Source: Internet
Author: User

 Number of daffodils Difficulty level: A; run time limit: 1000ms; operating space limit: 256000KB; code length limit: 2000000B Question Description The so-called Narcissus number is a three-digit number, the sum of the cubic of its figures equals itself. Enter a natural number n to output all daffodils with no more than N. If there is no output 0, if there are multiple, from small to large, 22 separated by a space. Input A positive integer n (no more than 1000). Output Output according to the requirements of the topic. Input example 200 Output example 153

A simple problem of circular judgment. You only need to start the loop from 100 to determine if the condition is met. But excitedly to hand it up, "output format is wrong"?! What kind of metaphysical mistake?!

There is a need to "set up a flag" here. Since multiple sequential output formats can be considered as "number, space, number of spaces, number of spaces, number of spaces ...". So a single flag is to determine whether the next should be output "number" or "number of spaces." At the same time, the flag can be used to determine whether the number of eligible conditions has been found. Because if found, the value of flag must be 1.

Code:

`#include <bits/stdc++.h>using namespace Std;bool flag;int i,n;int main () {scanf ("%d", &n); for (i=100;i<=n; i++)//from the smallest three digits to the end of N. {if (i%10) * (i%10) * (i%10) + (i/10%10) * (i/10%10) * (i/10%10) + (i/100%10) * (i/100%10) * (i/100%10) ==i)//Determine if the condition is met. {if (flag) printf ("");//is not the first number to output a space. flag=1;//indicates not the first number. printf ("%d", I);//outputs the number. }}if (!flag) printf ("0");//The output "0" was not found. return 0;}`

0067-Number of daffodils

Related Keywords:

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.