Advertisement
Guest User

Untitled

a guest
May 24th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.83 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <random>
  3.  
  4. using namespace std;
  5.  
  6. static const char justletters[] =
  7. "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  8. "abcdefghijklmnopqrstuvwxyz";
  9.  
  10. int justLettersLength= sizeof(justletters) - 1;
  11.  
  12. static const char tab[] =
  13. "0123456789"
  14. "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  15. "abcdefghijklmnopqrstuvwxyz";
  16.  
  17. int stringTab = sizeof(tab) - 1;
  18.  
  19. string tabBZ[4] = {" ", "\n", "\t", "\r"};
  20.  
  21. static const char alphanum[] =
  22. "0123456789"
  23. "!@#$%^&*"
  24. "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  25. "abcdefghijklmnopqrstuvwxyz";
  26.  
  27. string operacje[4] = {"NEW", "DEL", ">", "?"};
  28.  
  29. int stringLength = sizeof(alphanum) - 1;
  30.  
  31. #define SIZEO 10
  32.  
  33. void wylosujNumer() {
  34.   int iloscCharow = rand() % SIZEO + SIZEO;
  35.  
  36.   for (int i = 0; i < iloscCharow; i++) {
  37.     int c = rand() % 10;
  38.     cout << c;
  39.   }
  40. }
  41.  
  42. void wylosujID() {
  43.   int iloscCharow = rand() % SIZEO + SIZEO;
  44.  
  45.   for (int i = 0; i < iloscCharow; i++) {
  46.     int c = rand() % justLettersLength;
  47.     cout << justletters[c];
  48.   }
  49.  
  50.   iloscCharow = rand() % SIZEO + SIZEO;
  51.  
  52.   for (int i = 0; i < iloscCharow; i++) {
  53.     int c = rand() % stringTab;
  54.     cout << tab[c];
  55.   }
  56. }
  57.  
  58. void wylosujKomentarz() {
  59.   int iloscCharow = rand() % SIZEO + SIZEO;
  60.   cout << "$$";
  61.  
  62.   for (int i = 0; i < iloscCharow; i++) {
  63.     int c = rand() % stringLength;
  64.     cout << alphanum[c];
  65.   }
  66.  
  67.   int d = rand() % 1000;
  68.   if (d < 900) cout << "$$";
  69. }
  70.  
  71. void wylosujBialyZnak() {
  72.   int iloscCharow = rand() % SIZEO + SIZEO;
  73.  
  74.   for (int i = 0; i < iloscCharow; i++) {
  75.     int c = rand() % 4;
  76.     cout << tabBZ[c];
  77.   }
  78. }
  79.  
  80. void wylosujOperacje() {
  81.   int operation = rand() % 4;
  82.   string t = operacje[operation];
  83.  
  84.   if (operacje[operation] == ">") {
  85.     int l = rand() % 1000;
  86.     if (l < 950) {
  87.       wylosujNumer();
  88.     }
  89.   } else if (operacje[operation] == "?") {
  90.     int l = rand() % 1000;
  91.     if (l < 990) {
  92.       int p = rand() % 2;
  93.       if (p == 0) cout << operacje[operation];
  94.  
  95.       wylosujNumer();
  96.  
  97.       if (p != 0) cout << operacje[operation];
  98.     } else wylosujKomentarz();
  99.  
  100.     return;
  101.   }
  102.  
  103.   cout << operacje[operation];
  104.  
  105.   int k = rand() % 1000;
  106.   if (k < 990) wylosujBialyZnak();
  107.  
  108.   int p = rand() % 10000;
  109.   if (p > 9900) return;
  110.  
  111.   if (operacje[operation] == "NEW") {
  112.     wylosujID();
  113.   } else if (operacje[operation] == "DEL") {
  114.     int k = rand() % 1000;
  115.  
  116.     if (k > 10) {
  117.       wylosujNumer();
  118.     } else {
  119.       wylosujID();
  120.     }
  121.   } else {
  122.     wylosujNumer();
  123.   }
  124.  
  125.   k = rand() % 1000;
  126.   if (k < 990) wylosujBialyZnak();
  127. }
  128.  
  129. int main() {
  130.   long int seed;
  131.   cin >> seed;
  132.  
  133.   srand(seed * time(NULL));
  134.  
  135.   int iloscLinii = rand() % 1000 + 1000;
  136.  
  137.   int p = rand() % 100;
  138.   if (p < 95) cout << "NEW ID\n" << endl;
  139.  
  140.   for (int i = 0; i < iloscLinii; i++) {
  141.     int j = rand() % 500;
  142.     if (j > 300) wylosujKomentarz();
  143.  
  144.     wylosujOperacje();
  145.   }
  146.  
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement