jeg har lavet en ny. men dos menuen lukker hurtigt ned? man får ikke en chance for at se hvad der står?
min kode er
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include "conio.h"
using namespace std;
void test1(int m, int n)
{
vector<int> res;
for(int i = 0; i < m; i++)
{
int v;
do
{
v = rand() % n + 1;
}
while(find(res.begin(), res.end(), v) != res.end());
res.push_back(v);
}
sort(res.begin(), res.end());
for(int j = 0; j < res.size(); j++) cout << " " << res[j];
cout << endl;
}
void test2(int m, int n)
{
vector<int> res;
vector<int> base;
for(int k = 0; k < n; k++) base.push_back(k + 1);
for(int i = 0; i < m; i++)
{
int ix = rand() % base.size();
res.push_back(base[ix]);
base.erase(base.begin() + ix);
}
sort(res.begin(), res.end());
for(int j = 0; j < res.size(); j++) cout << " " << res[j];
cout << endl;
}
struct S
{
int v;
int r;
};
bool Scompare(S a, S b) { return (a.r < b.r); }
void test3(int m, int n)
{
vector<int> res;
vector<S> base;
for(int k = 0; k < n; k++)
{
S rec;
rec.v = k + 1;
rec.r = rand();
base.push_back(rec);
}
sort(base.begin(), base.end(), Scompare);
for(int i = 0; i < m; i++)
{
res.push_back(base[i].v);
}
sort(res.begin(), res.end());
for(int j = 0; j < res.size(); j++) cout << " " << res[j];
cout << endl;
}
int main()
{
srand(time(NULL));
test1(7, 36);
test2(7, 36);
test3(7, 36);
return EXIT_SUCCESS;
getch();
}