Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Nov 19th, 2018 67 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. #include <fstream>
  2. using namespace std;
  3.  
  4. ifstream fin("paranteze.in");
  5. ofstream fout("paranteze.out");
  6.  
  7. int n, a[20], cnti, cntd;
  8.  
  9. void ReadFunction();
  10. void Back(int k);
  11. void WriteFunction();
  12.  
  13. int main()
  14. {
  15.     ReadFunction();
  16.     Back(1);
  17. }
  18.  
  19. void ReadFunction()
  20. {
  21.     fin >> n;
  22. }
  23.  
  24. void Back(int k)
  25. {
  26.     if (k > n)
  27.     {
  28.         WriteFunction();
  29.         return;
  30.     }
  31.  
  32.     for (int i = 1; i <= 2; ++i)
  33.     {
  34.         if (i == 1 && cntd < n / 2)
  35.         {
  36.             a[k] = 1;
  37.            ++cntd;
  38.            Back(k + 1);
  39.            --cntd;
  40.         }
  41.         if (i == 2 && cnti < cntd)
  42.         {
  43.             a[k] = 2;
  44.             ++cnti;
  45.             Back(k + 1);
  46.             --cnti;
  47.         }
  48.     }
  49. }
  50.  
  51. void WriteFunction()
  52. {
  53.     for (int i = 1; i <= n; ++i)
  54.     {
  55.         switch(a[i])
  56.         {
  57.             case 1: fout << "(";
  58.                 break;
  59.             case 2: fout << ")";
  60.         }
  61.     }
  62.     fout << '\n';
  63. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top