Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // свой ГСПЧ
- // создаст массив из n 7-ми значных эл-тов
- // этот .cpp должен создать этот массив и закинуть его в файл в этой директории
- #include <iostream>
- #include <ctime>
- #include <random>
- #include <fstream>
- using namespace std;
- char num_sym(long v);
- long RSDN();
- void create_file();
- int main()
- {
- setlocale(0, "");
- create_file();
- return 0;
- }
- void create_file()
- {
- unsigned int start_time = clock(); // начальное время
- srand(time(0));
- ofstream f("10000.txt");
- for (int i = 0; i < 10000000; i++)
- {
- f << RSDN() << " ";
- }
- f.close();
- unsigned int end_time = clock(); // конечное время
- double search_time = (end_time - start_time) / 1000; // искомое время в секундах
- cout << "time: " << search_time << "\n\n";
- cout << "\n\nФайл создан!\n\n";
- }
- char num_sym(long v) // считает кол-во символов
- {
- char count = 1;
- while (v > 9)
- {
- count++;
- v /= 10;
- }
- return count;
- }
- long RSDN()
- {
- long x;
- x = rand();
- unsigned int count_sym = num_sym(x); // кол-во символов
- if (count_sym == 1)
- {
- x = 1000000;
- }
- else if (count_sym < 7) // если кол-во символов < 7
- {
- x = x * pow(10, 7 - count_sym) + 1;
- }
- else if (count_sym > 7) // если кол-во символов > 7
- {
- x /= pow(10, count_sym - 7);
- }
- return x;
- }
- // pract1_4.cpp
- #include <iostream>
- #include <fstream>
- #include <ctime>
- using namespace std;
- const unsigned int SIZE = 10 * 1000 * 1000; // размер массива
- const unsigned int MIN_NUM = 1000 * 1000; // минимальное 7-мизначное число
- const unsigned int MAX_NUM = 10 * 1000 * 1000; // максимальное 7-мизначное число + 1
- const unsigned int CONTROL = 842150451 - 10 * 1000 * 1000;
- void sort();
- void countingSort(int* array, int n);
- int main()
- {
- unsigned int start_t = clock(); // начальное время
- sort();
- unsigned int end_t = clock(); // конечное время
- unsigned int search_t = (end_t - start_t); // искомое время в мс
- cout << "full time: " << search_t << "\n\n";
- return 0;
- }
- void sort()
- {
- int* a = new int[SIZE];
- //long long* c = new long long[MAX_NUM]();
- long long* arr = new long long[MAX_NUM](); // создание массива, заполненного нулями
- /*
- int** arr = new int* [2]; // кол-во строк
- for (int i = 0; i < 2; i++)
- {
- arr[i] = new int[MAX_NUM]; // кол-во столбцов
- }
- for (int i = 0; i < 2; i++)
- {
- for (int j = 0; j < MAX_NUM; j++)
- {
- arr[i][j] = 0;
- }
- }
- */
- long long x = 0;
- long long count = 0;
- ifstream in("10000.txt");
- while (in.good())
- {
- in >> x; // считывает число из файла
- a[count] = x; // считает кол-во чисел
- count++;
- //cout << x << " " << arr[x] << "\n";
- //system("pause");
- }
- in.close();
- long long* c = new long long[MAX_NUM]();
- for (int i = 0; i < SIZE; i++)
- {
- c[a[i]]++;
- }
- int b = 0;
- for (int i = 0; i < SIZE; i++) {
- for (int j = 0; j < c[i]; j++) {
- arr[b] = i;
- b = b + 1;
- }
- }
- ofstream out("sort.txt");
- /*
- for (long long i = 0; i < MAX_NUM; i++)
- {
- for (long long j = 0; j < c[i]; j++) // если кол-во чисел > 0, срабатывает столько раз, сколько это число встречается
- {
- out << i << " "; // записывает числа в файл
- }
- }
- */
- for (int i = 0; i < SIZE; i++)
- {
- out << arr[i] << " ";
- }
- out.close();
- delete[] arr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement