imreally_john

generator.cpp

Jul 26th, 2020 (edited)
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <fstream>
  3. #include <stdlib.h>
  4. using namespace std;
  5. typedef long long int ll;
  6.  
  7. #define pb push_back
  8.  
  9. const ll MAX = 1e5;
  10.  
  11. ll randomRange(ll lower, ll upper)
  12. {
  13.     ll num = (rand() % (upper - lower + 1)) + lower;
  14.     return num;
  15. }
  16.  
  17. char randchar(char lower, char upper)
  18. {
  19.     char num = (rand() % (upper - lower + 1)) + lower;
  20.     return num;
  21. }
  22.  
  23. string randomChoice(ll probability, ll n)
  24. {
  25.     string s;
  26.     for (int i = 0; i < n; i++)
  27.         s += randchar('0', '1');
  28.     return s;
  29. }
  30.  
  31. int main()
  32. {
  33.     ofstream fout, fin;
  34.     fin.open("input_P(3).in"); // The input filename
  35.     fout.open("output_P(3).out"); // The output filename
  36.  
  37.     ll n = randomRange(1, 1e3);
  38.     fin << n << endl;
  39.     vector<string> s(n);
  40.     for (int i = 0; i < n; i++)
  41.     {
  42.         s[i] = randomChoice(randomRange(1, 10), randomRange(1, 1e3));
  43.         fin << s[i];
  44.         fin << endl;
  45.     }
  46.     for (int i = 0; i < s.size(); i++)
  47.     {
  48.         if (s[i][0] == '0')
  49.         {
  50.             fout << 0 << endl;
  51.         }
  52.         else
  53.         {
  54.             ll ans = 0, flag0 = 0, flag1 = 0;
  55.             for (int j = 0; j < s[i].size(); j++)
  56.             {
  57.                 if (s[i][j] == '1')
  58.                 {
  59.                     if (ans != 0)
  60.                         break;
  61.                     flag1 = 1;
  62.                 }
  63.                 else
  64.                 {
  65.                     flag0 = 1;
  66.                     if (flag1 and s[i][j] == '0')
  67.                         ans++;
  68.                 }
  69.             }
  70.             fout << ans << endl;
  71.         }
  72.     }
  73.     fin.close();
  74.     fout.close();
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment