在1-50万的编号里摇号,输出前n个尾号为55和77的编号

来源:互联网 发布:手机淘宝首页切图模块 编辑:程序博客网 时间:2024/04/29 06:46
#include "iostream"#include "ctime"#include "cstdlib"using namespace std;#define N 10int main(){int num[N] = {0};int count = 0; //计数int random = 0; //生成的随机数bool flag = false; //随机数是否存在的标记srand((unsigned)time(0)); //播种子while(count < N){random = ( rand() % (500000 - 1 + 1) ) + 1; //生成1-500000内的随机数 flag = false;if(random % 100 == 55 || random % 100 == 77) //截取随机数后两位进行判断{for(int i = 0; i < count; i++) //若找到了判断是否已存在{if(num[i] == random){flag = true;break;}}if(!flag)   //不存在则记录num[count] = random;elsecontinue;}else{continue;}count++;}for(int i = 0; i < N; i++){cout<<num[i]<<"\t";}system("pause");return 0;}

0 0
原创粉丝点击