Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <math.h>
- #include <chrono>
- #include <ctime>
- using namespace std;
- char * randgen(int u, char * word){
- srand(time(NULL));
- cout << "a" << endl;
- for (int i=0; i<u; i++){
- chrono::time_point<chrono::system_clock> now = chrono::system_clock::now();
- auto duration = now.time_since_epoch();
- auto nanoseconds = chrono::duration_cast<chrono::nanoseconds>(duration);
- srand(nanoseconds.count());
- word[i] = 'a' + (rand() % 25);
- }
- cout << "b" << endl;
- word[u] = '\0';
- return word;
- }
- char * worstgen(int v , string C1, string C2){
- char * arr = new char[v];
- string strings[2] = {C1, C2};
- int totdivsize = 2;
- while (totdivsize < 2*C1.size()){
- totdivsize *=2;
- }
- int h,k;
- int totdiv = v/totdivsize;
- for ( int i = 0; i < totdiv; i++){
- h = 1;
- k = 0;
- for ( int j = i*totdivsize; j < i*totdivsize+2*C1.size() - 1; j++){
- arr[j] = strings[h][k];
- if ( h == 1) k++;
- h = (h+1)%2;
- }
- int e = (totdivsize-2*C1.size()-1 );
- if ( e > 0){
- string fill = randgen(totdivsize-2*C1.size()-1, new char[3]);//le he metido el new char[3] para que compile pero no pinta nada
- for (int j = i*totdivsize + 2*C1.size() - 1; j < totdivsize*(i+1) - 1; j++) arr[j] = fill[j-(i*totdivsize+2*C1.size() - 1)];
- arr[(i+1)*totdivsize-1] = strings[0][0];
- }
- else {
- arr[(i+1)*totdivsize-1] = strings[0][0];
- }
- }
- return arr;
- }
- char * bestgen(int v, string C1, string C2) {
- char * arr = new char[v];
- string strings[2] = {C1, C2};
- int totdivsize = 2;
- while (totdivsize < 2*C1.size()) {
- totdivsize *= 2;
- }
- int h, k;
- int totdiv = v/totdivsize;
- for (int i = 0; i < totdiv; i++) {
- h = k = 0;
- for (int j = i*totdivsize; j < i*totdivsize+2*C1.size(); j++) {
- arr[j] = strings[h][k];
- if ( h == 1) k++;
- h=(h+1)%2;
- }
- string fill = randgen(totdivsize-2*C1.size(), new char[3]); //le he metido el new char[3] para que compile pero no pinta nada
- for (int j = i*totdivsize + 2*C1.size(); j < totdivsize*(i+1); j++) arr[j] = fill[j-(i*totdivsize+2*C1.size())];
- }
- return arr;
- }
- int main() {
- int n = 100000;
- int m = 200;
- int b = 2*m;
- char * C1 = new char[m];
- char * C2 = new char[m];
- randgen(m, C1);
- randgen(m, C2);
- cout << b << endl;
- cout << randgen(n, new char[n]) << endl;
- cout << C1 << endl << C2 << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement