Last active
November 5, 2019 08:36
-
-
Save pinglunliao/5a0bf2773f36d1b0608b to your computer and use it in GitHub Desktop.
a040: 阿姆斯壯數 FYI: https://yunlinsong.blogspot.com/2016/02/blog-post_11.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
int armstrongNum[] = { | |
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, | |
153, 370, 371, 407, | |
1634, 8208, 9474, | |
54748, 92727, 93084, | |
548834 | |
}; | |
short SIZE = sizeof(armstrongNum) / sizeof(int); | |
bool isArmstrong[1000000]; | |
for(int i = 0; i < SIZE; i++) | |
isArmstrong[armstrongNum[i]] = true; | |
int a, b; | |
while(cin >> a >> b) | |
{ | |
bool hasArm = false; | |
for( ; a <= b; a++ ) | |
{ | |
if(isArmstrong[a]) | |
{ | |
cout << a << " "; | |
hasArm = true; | |
} | |
} | |
if(!hasArm) | |
cout << "none"; | |
cout << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment