-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshuffle.cpp
More file actions
30 lines (24 loc) · 727 Bytes
/
shuffle.cpp
File metadata and controls
30 lines (24 loc) · 727 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <time.h>
#include <vector>
std::ifstream fin("shuffle.in");
std::ofstream fout("radix.in");
int myrandom(int i) { return std::rand() % i; }
int main() {
clock_t tStart = clock();
std::srand(unsigned(std::time(0)));
int array[1000]; // C-style array of integers
for (int i = 0; i < 1000; i++) {
fin >> array[i]; // sfin
}
std::vector<int> vec(array,
array + 1000); // build STL container from int array
std::random_shuffle(array, array + 1000, myrandom);
for (int i = 0; i <= 1000; i++) {
fout << array[i] << " "; // rfout
}
printf("\n\nTimp: %.2f ms\n", (double)(clock() - tStart));
}