#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
using namespace std;
int main()
{
int n;
cin >> n;
vector <int> number(n, 0);
vector <string> person = {"aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii"};
srand((unsigned)time(NULL));
for (int i = 0; i < n; i++)
number[i] = rand();
for (int i = 0; i < n-1; i++)
{
for (int j = i+1; j < n; j++)
{
if (number[i] < number[j])
{
int tempInt = number[i];
number[i] = number[j];
number[j] = tempInt;
string tempString = person[i];
person[i] = person[j];
person[j] = tempString;
}
}
}
cout << "随机生成的的人员顺序:" << endl;
for (int i = 0; i < person.size(); i++)
cout << i+1 << ": " << person[i] << " " << endl;
cout << endl << endl;
int next; // 输入任意,无影响
srand((unsigned)time(NULL));
while (cin >> next)
{
next = rand() % n;
cout << "序号: " << next + 1 << endl;
cout << "姓名: " << person[next] << endl << endl;
}
system("pause");
}
c++随机抽人代码
最新推荐文章于 2024-04-23 21:31:45 发布