水仙花数
来源:互联网 发布:nginx php exec 编辑:程序博客网 时间:2024/05/13 05:12
水仙花数又称阿姆斯特朗数。
水仙花数是指一个n 位数( n≥3 ),它的每个位上的数字的n 次幂之和等于它本身。(例如:1^3 + 5^3 + 3^3 = 153)
求输入的数字是否为水仙花数
#include <stdlib.h>#include "oj.h"#include <vector>#include <math.h>using namespace std;// 功能:判断输入 nValue 是否为水仙花数// 输入: nValue为正整数// 输出:无// 返回:如果输入为水仙花数,返回1,否则返回0unsigned int IsDaffodilNum(unsigned int nValue){int bitNum = 0;unsigned int value = nValue;vector<int> bit;while(value){bit.push_back(value%10);value /= 10;++bitNum;}if(bitNum < 3)return 0;value = 0;for(vector<int>::iterator it = bit.begin();it != bit.end();++it){value += static_cast<int>(pow(static_cast<float>(*it),bitNum));}if(value == nValue)return 1;elsereturn 0;}
0 0
- 水仙花数
- 水仙花数
- 水仙花数
- 水仙花数
- 水仙花数
- 水仙花数
- 水仙花数
- 水仙花数
- 水仙花数
- 水仙花数
- 水仙花数
- 水仙花数
- 水仙花数
- 水仙花数
- 水仙花数
- 水仙花数
- 水仙花数
- 水仙花数
- [leetcode]Min Stack (获取栈的最小元素C语言实现)
- 你的团队太大还是太小?
- Xcode6中添加pch文件
- ios中利用NSDateComponents、NSDate、NSCalendar判断当前时间是否在一天的某个时间段内
- 最小生成树--普里姆算法
- 水仙花数
- http://blog.csdn.net/wsh900221/article/details/23285283
- 【Sublime】Sublime Text 插件添加/移除方法
- 联名账户
- iOS开发之深入探讨runtime机制01-类与对象
- 项目中知识点的总结
- Python 函数
- 最新随笔 最新评论 Class.forName的作用以及为什么要用它
- Freemarker详解