随机座位表

发布于 2019-01-13  2591 次阅读


搞了一个班上生成座位的东西

总之是有一对男女同桌和一个单人位

大概是随机的吧

#include <stdio.h>
#include <cstring>
#include <windows.h>
#include <string>
#include <iostream>
#include <stdlib.h>
#include <time.h>
#define random(x) (rand()%x)
using namespace std;
string name[51] = {} 
bool f[51] = {1,0,1,0,1,1,1,0,0,0,0,0,0,0,1,1,0,0,1,0,0,1,0,0,0,0,0,1,1,0,1,0,1,1,1,1,0,1,1,0,0,0,0,1,0,0,1,1,1,0,1};
bool fl[51];
int find(int x)
{
	while (fl[x] == 1 && x < 50)
		x++;
	return x;
}
int main()
{
	freopen("name.txt", "w", stdout);
    srand((int)time(0));
    int x = random(51), y = random(51);
    while (x == y || f[x] == f[y] || x == 9 || y == 9)
    {
    	x = random(51);
		y = random(51);
	}
    fl[x] = fl[y] = 1;
    cout << name[x] << ' ' << name[y] << endl;
	for (int i = 1; i <= 24; i++)
	{
		x = random(51), y = random(51);
   		while (x == y || f[x] != f[y] || x == 9 || y == 9 || fl[x] == 1 || fl[y] == 1)
    	{
    		Sleep(5);
    		x = find(random(51));
    		Sleep(5);
			y = find(random(51));
		}
		fl[x] = fl[y] = 1;
   		cout << name[x] << ' ' << name[y] << endl;
   		if (i == 5 || i == 12 || i == 18) printf("\n");
   		Sleep(5);
	}
	cout << name[9] << endl;
    fclose(stdout);
    system("start name.txt");
}

 

「雪霁融雾月,冰消凝夜雨」
最后更新于 2019-03-08