標題:
a040: 阿姆斯壯數
[打印本頁]
作者:
buy
時間:
2010-10-16 08:42
標題:
a040: 阿姆斯壯數
本帖最後由 buy 於 2010-10-16 11:58 編輯
內容 : 正體->简体
所謂 Armstrong number 指的是一個 n 位數的整數,它的所有位數的 n 次方和恰好等於自己。
如;1634 = 14 + 64 + 34+ 44
請依題目需求在一定範圍內找出該範圍內的所有 armstrong numbers.
輸入說明 :
輸入包含兩個數字n, m(n<m, n>0, m<=1000000),代表所有尋找 armstrong number 的範圍
輸出說明 :
將所有範圍內的 armstrong number 依序由小到大輸出,如果沒有找到請輸出 none.
範例輸入 :
100 999 10 99
範例輸出 :
153 370 371 407 none
------------------------------------------------------------------------------------------
1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634, 8208, 9474, 54748, 92727, 93084, 548834, 1741725, 4210818, 9800817, 9926315, 24678050, 24678051, 88593477, 146511208, 472335975, 534494836, 912985153, 4679307774, 32164049650, 32164049651
1.先找出左邊界
2. 找出右邊界
3. 將界限內的 armstrong number 印出來
--------------------------------------------------------------
long Value[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370,
371, 407, 1634, 8208, 9474, 54748, 92727,
93084, 548834, 1741725, 4210818, 9800817, 9926315,
24678050, 24678051, 88593477, 146511208, 472335975 };
long a,b;
int Lower,Upper;
while( cin >> a >> b )
{
...
//判斷Upper,Lower
if(Upper < Lower)
{
cout << "none" << endl;
}
else
{
for (i =Lower ; i<= Upper ; i++)
{
cout << Value[i] << " ";
}
cout << endl;
}
}
複製代碼
作者:
chuangjoy
時間:
2010-10-16 12:01
本帖最後由 chuangjoy 於 2010-10-16 12:02 編輯
#include <iostream>
using namespace std;
int main(){
long Value[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370,
371, 407, 1634, 8208, 9474, 54748, 92727,
93084, 548834, 1741725, 4210818, 9800817, 9926315,
24678050, 24678051, 88593477, 146511208, 472335975 };
long a,b;
int Lower,Upper;
while(cin >> a >> b )
{
for(int i = 0; i <= 29; i++){
if(Value[i] < a){
break;
}else{
Upper = i;
}
}
for(int i = 29; i >= 0; i--){
if(Value[i] > b){
break;
}else{
Lower = i;
}
}
//判斷Upper,Lower
if(Upper < Lower){
cout << "none" << endl;
}else{
for (int i = Lower; i <= Upper; i++){
cout << Value << " ";
}
cout << endl;
}
}
return 0;
}
複製代碼
這是錯的~
一直無窮回圈~
= =
作者:
Alen
時間:
2010-10-16 12:25
#include<iostream>
using namespace std;
main(){
int value[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370,
371, 407, 1634, 8208, 9474, 54748, 92727,
93084, 548834, 1741725, 4210818, 9800817, 9926315,
24678050, 24678051, 88593477, 146511208, 472335975 };
long a,b;
int c[29] = {0};
int k = 0;
while( cin >> a >> b ){
if (a > b){
cout << "none" << endl;
}else{
for (int i = 0;i <= 29;i++){
if (value[i] >= a && value[i] <= b){
c[k]= value[i];
k++;
}
}cout << endl;
if (k == 0){
cout << "none" << endl;
}else{
for (int i = 0;i < k;i++){
cout << c[i] << " ";
}cout << endl;
}
}
}
}
複製代碼
作者:
buy
時間:
2010-10-30 11:22
#include <iostream>
using namespace std;
int main(){
long Value[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370,
371, 407, 1634, 8208, 9474, 54748, 92727,
93084, 548834, 1741725, 4210818, 9800817, 9926315,
24678050, 24678051, 88593477, 146511208, 472335975 };
long a,b;
int Lower=0,Upper=0;
while(cin >> a >> b )
{
for(int i = 0; i < 29; i++){
if(Value[i] <= a){
Lower = i;
}else{
break;
}
}
for(int i = 28; i >= 0; i--){
if(Value[i] <= b){
break;
}else{
Upper = i;
}
}
if(Value[Lower] != a)
{
Lower++;
}
//判斷Upper,Lower
Upper--;
//Lower++;
//cout << Lower << "," << Upper << ".";
if(Upper < Lower){
cout << "none" << endl;
}else{
for (int i = Lower; i <= Upper; i++){
cout << Value[i] << " ";
}
cout << endl;
}
}
//system("pause");
return 0;
}
複製代碼
作者:
chuangjoy
時間:
2010-10-30 11:24
#include <iostream>
using namespace std;
int main(){
long Value[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370,
371, 407, 1634, 8208, 9474, 54748, 92727,
93084, 548834, 1741725, 4210818, 9800817, 9926315,
24678050, 24678051, 88593477, 146511208, 472335975 };
long a,b;
int Lower=0,Upper=0;
while(cin >> a >> b )
{
for(int i = 0; i < 29; i++){
if(Value[i] <= a){
Lower = i;
}else{
break;
}
}
for(int i = 28; i >= 0; i--){
if(Value[i] <= b){
break;
}else{
Upper = i;
}
}
if(Value[Lower] != a)
{
Lower++;
}
//判斷Upper,Lower
Upper--;
//Lower++;
//cout << Lower << "," << Upper << ".";
if(Upper < Lower){
cout << "none" << endl;
}else{
for (int i = Lower; i <= Upper; i++){
cout << Value[i] << " ";
}
cout << endl;
}
}
//system("pause");
return 0;
}
複製代碼
作者:
p17johnny
時間:
2010-10-30 11:25
#include <iostream>
using namespace std;
int main(){
long Value[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370,
371, 407, 1634, 8208, 9474, 54748, 92727,
93084, 548834, 1741725, 4210818, 9800817, 9926315,
24678050, 24678051, 88593477, 146511208, 472335975 };
long a,b;
int Lower=0,Upper=0;
while(cin >> a >> b )
{
for(int i = 0; i < 29; i++){
if(Value[i] <= a){
Lower = i;
}else{
break;
}
}
for(int i = 28; i >= 0; i--){
if(Value[i] <= b){
break;
}else{
Upper = i;
}
}
if(Value[Lower] != a)
{
Lower++;
}
//判斷Upper,Lower
Upper--;
//Lower++;
//cout << Lower << "," << Upper << ".";
if(Upper < Lower){
cout << "none" << endl;
}else{
for (int i = Lower; i <= Upper; i++){
cout << Value[i] << " ";
}
cout << endl;
}
}
//system("pause");
return 0;
}
複製代碼
作者:
Alen
時間:
2010-10-30 11:27
回復
4#
buy
#include <iostream>
using namespace std;
int main(){
long Value[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370,
371, 407, 1634, 8208, 9474, 54748, 92727,
93084, 548834, 1741725, 4210818, 9800817, 9926315,
24678050, 24678051, 88593477, 146511208, 472335975 };
long a,b;
int Lower=0,Upper=0;
while(cin >> a >> b )
{
for(int i = 0; i < 29; i++){
if(Value[i] <= a){
Lower = i;
}else{
break;
}
}
for(int i = 28; i >= 0; i--){
if(Value[i] <= b){
break;
}else{
Upper = i;
}
}
if(Value[Lower] != a)
{
Lower++;
}
//判斷Upper,Lower
Upper--;
//Lower++;
//cout << Lower << "," << Upper << ".";
if(Upper < Lower){
cout << "none" << endl;
}else{
for (int i = Lower; i <= Upper; i++){
cout << Value[i] << " ";
}
cout << endl;
}
}
//system("pause");
return 0;
}
複製代碼
作者:
小乖乖w
時間:
2011-7-9 02:28
很不错,值得鼓励,。。。
芳草集眼霜
芳草集怎么样
芳草集官网
淘宝网芳草集
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2