[HDU] [2010] Narcissistic Numbers

Problem Description

Loading...

Problem Analysis

The interesting part of this problem is that it uses a kind of “switch” variable I used back when I wrote bots in E-language (Yi Yuyan) though looking back, it seems some of the senior students’ code used this concept too There are other ways to judge this problem as well but feeling that the knowledge from before is useful still makes me quite happy

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include<stdio.h>
int main() {
    int i,m,n,x,a,b,c;
    while(scanf("%d %d",&m,&n)!=EOF) {
        x=0;
        for(i=m; i<=n; i++) {
            a=i%10;
            b=(i%100)/10;
            c=i/100;
            if(a*a*a+b*b*b+c*c*c==i) {
                if(x==1)
                    printf(" ");
                x=1;
                printf("%d",i);

            }
        }
        if(x!=1)
            printf("no");
        printf("\n");
    }
    return 0;
}

Loading...