现有小于999的任意500个整数,如何能筛选出小于999的另外500个整数?
来源:百度知道 编辑:UC知道 时间:2024/07/02 10:40:13
main()
{
int exists[500];
int otherint[500];
int index=0;
int temp;
bool numexist=false;
//.....初始化exists数组
while (index<500)
{
randomize();
temp=random(999);
//检查exists数组
for (int i=0;i<500;i++)
{
if (temp==exists[i])//标志已经存在
{
numexist=true;
break;
}
}
//检查otherint数组
for (int i=0;i<index;i++)
{
if (temp==otherint[i])//标志已经存在
{
numexist=true;
break;
}
}
if (!numexist) //如果不存在
{
otherint[index++]=temp;
numexist=false;//重新置为假
}
}
}
你是指在程序中么?有很多种做法啦
一种是可以建立一个下标为999的布尔数组,全置为True,然后凡是输入整数的对应布尔值置为False,最后输出全部为True的就是另外500个整数啦。
还可以建立一个字符串,中间以某个符号相隔,比如1*2*3...*999,然后凡是输入的全部替换掉,比如 replace(str,"214",""),留下来的字符串加以整理再输出