Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- ifstream fin("paranteze.in");
- ofstream fout("paranteze.out");
- int n, a[20], cnti, cntd;
- void ReadFunction();
- void Back(int k);
- void WriteFunction();
- int main()
- {
- ReadFunction();
- Back(1);
- }
- void ReadFunction()
- {
- fin >> n;
- }
- void Back(int k)
- {
- if (k > n)
- {
- WriteFunction();
- return;
- }
- for (int i = 1; i <= 2; ++i)
- {
- if (i == 1 && cntd < n / 2)
- {
- a[k] = 1;
- ++cntd;
- Back(k + 1);
- --cntd;
- }
- if (i == 2 && cnti < cntd)
- {
- a[k] = 2;
- ++cnti;
- Back(k + 1);
- --cnti;
- }
- }
- }
- void WriteFunction()
- {
- for (int i = 1; i <= n; ++i)
- {
- switch(a[i])
- {
- case 1: fout << "(";
- break;
- case 2: fout << ")";
- }
- }
- fout << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement