美文网首页
水仙花数

水仙花数

作者: 黑夜与繁星 | 来源:发表于2018-03-25 14:36 被阅读7次
sample.png
#include <bits/stdc++.h>
using namespace std;
int cube(int n){
    return n*n*n;
}

bool isflower(int i){
    int unit,decade,hundred,temp;
    temp=i;
    hundred=i/100; 
    i%=100; 
    decade=i/10;
    i%=10; 
    unit=i;
    if(cube(unit)+cube(decade)+cube(hundred)==temp){
        return true;
    }
    
    return false;
}

void putnum(int m,int n){
    //bool find=false;
    int cnt=0;
    for(int i = m;i<=n;i++){
        if(isflower(i)){
            cnt++;
            if(cnt==1){
                cout<<i;
            }else{
                cout<<" "<<i;
            }           
        }
    }
    
    if(cnt==0){
        cout<<"no";
    }
}

int main(){
    int m,n;
    while(scanf("%d%d",&m,&n)==2){
        putnum(m,n); 
        cout<<endl;       
    }
    return 0;
}

相关文章

  • 算法题目-水仙花数

    题目: 打印出所有的水仙花数 水仙花数 水仙花数(Narcissistic number)也被称为超完全数字不变...

  • JS代码题15——水仙花数

    给出n,找到所有的n位十进制水仙花数。 样例: 首先,什么是水仙花数? 在数论中,水仙花数(Narcissisti...

  • 水仙花问题 -- Java描述

    水仙花问题 -- Java描述 题目: 编程求出 100~999 的所有的水仙花数(所谓“水仙花数”是指一个3位数...

  • Rust语言编程实例100题-013

    Rust语言编程实例100题-013 题目:经典水仙花数问题。打印出所有的"水仙花数",所谓"水仙花数"是指一个三...

  • Java 复习题

    1.水仙花数 打印出100-999所有的“水仙花数”。 思路: 水仙花数是指一个 n 位数 ( n≥3 ),它的每...

  • 水仙花数——Python

    水仙花数打印出 100-999 所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数 字立方和等于该数本身...

  • 【Java基础】-案例学习

    案例1:在控制台输出所有的“水仙花数” 什么是水仙花数:1.水仙花数是一个三位数,如:111,222,333,37...

  • Python 练习作业 001

    #练习 '''从控制台输入一个三位数,如果是水仙花数就打印“是水仙花数”,否则打印“不是水仙花数”153=1^3...

  • 自学Python:寻找水仙花数

    什么是水仙花数? 水仙花数是指一个三位数,其各位数字的立方和等于该数本身,例如,153是“水仙花数”,因为153=...

  • Java案例-求出所有的水仙花数

    Java案例 求出所有的水仙花数 案例分析 输出水仙花数,所谓的水仙花数是指一个3位数,其各个位数立方和等于其本身...

网友评论

      本文标题:水仙花数

      本文链接:https://www.haomeiwen.com/subject/omwhcftx.html