#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h>
void random_set(int data[], size_t size) {
for(size_t i = 0; i < size; ++i) {
data[i] = rand() % 33 + 1;
}
}
bool verify(int data[], size_t size) {
for(size_t i = 0; i < size; ++i) {
for(size_t j = i + 1; j < size; ++j) {
if(data[i] == data[j]) return false;
}
}
return true;
}
int main() {
srand(time(NULL));
int red_ball[6];
int blue_ball;
for(size_t i = 0; i < 10; i++) {
while(true) {
random_set(red_ball, 6);
if(verify(red_ball, 6)) break;
}
blue_ball = rand() % 16 + 1;
printf("******************************************************************************\n");
printf("第%lu组号码:\n", i + 1);
printf("红球号码为:");
for(size_t i = 0; i < 6; ++i) {
printf("\t%d", red_ball[i]);
}
puts("");
printf("篮球号码为:\t%d\n", blue_ball);
printf("******************************************************************************\n");
}
return 0;
}
|