您的位置:首页 > 其它

POJ-1316

2015-08-02 16:00 260 查看
#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: