首页 > 其他 > 详细

POJ-1316

时间:2015-08-02 16:48:28      阅读:227      评论:0      收藏:0      [点我收藏+]
#include<iostream>
using namespace std;

bool selfNum[10000];

bool findNoneSelfNum(int index){
	int one,ten,hundred,thousand;

	if(index>=10000){
		return false;
	}

	if(selfNum[index]==false){
		return true;
	}

	thousand=index/1000;
	hundred=(index-thousand*1000)/100;
	ten=(index-thousand*1000-hundred*100)/10;
	one=index-thousand*1000-hundred*100-ten*10;

	int noneSelfNum=index+thousand+hundred+ten+one;
	if(noneSelfNum<10000){
		findNoneSelfNum(noneSelfNum);
		selfNum[noneSelfNum]=false;
	}else{
		return false;
	}
}

int main(int argc, char *argv[]){
	for(int i=1;i<10000;i++){
		selfNum[i]=true;
	}

	for(int i=1;i<10000;i++){
		findNoneSelfNum(i);
	}

	for(int i=1;i<10000;i++){
		if(selfNum[i]){
			cout<<i<<endl;
		}
	}

	return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

POJ-1316

原文:http://blog.csdn.net/eddy_liu/article/details/47208093

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!