Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <math.h>
  4. #include <chrono>
  5. #include <ctime>
  6.  
  7. using namespace std;
  8.  
  9. char * randgen(int u, char * word){
  10. srand(time(NULL));
  11. cout << "a" << endl;
  12. for (int i=0; i<u; i++){
  13. chrono::time_point<chrono::system_clock> now = chrono::system_clock::now();
  14. auto duration = now.time_since_epoch();
  15. auto nanoseconds = chrono::duration_cast<chrono::nanoseconds>(duration);
  16. srand(nanoseconds.count());
  17. word[i] = 'a' + (rand() % 25);
  18. }
  19. cout << "b" << endl;
  20. word[u] = '\0';
  21. return word;
  22. }
  23.  
  24. char * worstgen(int v , string C1, string C2){
  25. char * arr = new char[v];
  26. string strings[2] = {C1, C2};
  27. int totdivsize = 2;
  28. while (totdivsize < 2*C1.size()){
  29. totdivsize *=2;
  30. }
  31. int h,k;
  32. int totdiv = v/totdivsize;
  33. for ( int i = 0; i < totdiv; i++){
  34. h = 1;
  35. k = 0;
  36. for ( int j = i*totdivsize; j < i*totdivsize+2*C1.size() - 1; j++){
  37. arr[j] = strings[h][k];
  38. if ( h == 1) k++;
  39. h = (h+1)%2;
  40. }
  41. int e = (totdivsize-2*C1.size()-1 );
  42. if ( e > 0){
  43. 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
  44. 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)];
  45. arr[(i+1)*totdivsize-1] = strings[0][0];
  46. }
  47. else {
  48. arr[(i+1)*totdivsize-1] = strings[0][0];
  49. }
  50. }
  51. return arr;
  52. }
  53. char * bestgen(int v, string C1, string C2) {
  54. char * arr = new char[v];
  55. string strings[2] = {C1, C2};
  56. int totdivsize = 2;
  57. while (totdivsize < 2*C1.size()) {
  58. totdivsize *= 2;
  59. }
  60.  
  61. int h, k;
  62. int totdiv = v/totdivsize;
  63. for (int i = 0; i < totdiv; i++) {
  64. h = k = 0;
  65. for (int j = i*totdivsize; j < i*totdivsize+2*C1.size(); j++) {
  66. arr[j] = strings[h][k];
  67. if ( h == 1) k++;
  68. h=(h+1)%2;
  69. }
  70. string fill = randgen(totdivsize-2*C1.size(), new char[3]); //le he metido el new char[3] para que compile pero no pinta nada
  71. for (int j = i*totdivsize + 2*C1.size(); j < totdivsize*(i+1); j++) arr[j] = fill[j-(i*totdivsize+2*C1.size())];
  72. }
  73. return arr;
  74. }
  75.  
  76. int main() {
  77. int n = 100000;
  78. int m = 200;
  79. int b = 2*m;
  80. char * C1 = new char[m];
  81. char * C2 = new char[m];
  82. randgen(m, C1);
  83. randgen(m, C2);
  84. cout << b << endl;
  85. cout << randgen(n, new char[n]) << endl;
  86. cout << C1 << endl << C2 << endl;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement