-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindrome_Reorder.cpp
More file actions
86 lines (79 loc) · 1.91 KB
/
Palindrome_Reorder.cpp
File metadata and controls
86 lines (79 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// #include<bits/stdc++.h>
// using namespace std;
// typedef long long ll;
// bool canFormPalindrome(string str){
// int n =str.size();
// unordered_map<char,int> mp;
// for(int i=0;i<n;i++){
// mp[str[i]]++;
// }
// int oddCnt=0;
// for(auto i:mp){
// if(i.second%2){
// oddCnt++;
// if(oddCnt>1) return false;
// }
// }
// return true;
// }
// void solve(string str){
// if(!canFormPalindrome(str)){
// cout<<"NO SOLUTION"<<endl;
// return;
// }
// unordered_map<char,int> mp;
// string left,mid,right;
// for(int i=0;i<str.size();i++){
// mp[str[i]]++;
// }
// for(auto i:mp){
// char c=i.first;
// int count=i.second;
// if(count%2==0){
// left.append(count/2,c);
// right.insert(0,count/2,c);
// }
// else{
// mid=c;
// left.append((count-1)/2,c);
// right.insert(0,(count-1)/2,c);
// }
// }
// cout<<left<<mid<<right<<endl;
// }
// int main(){
// ios_base::sync_with_stdio(false);cin.tie(NULL);
// ll t;
// // cin>>t;
// t=1;
// while(t--){
// string str;
// cin>>str;
// solve(str);
// }
// return 0;
// }
#include <iostream>
#include <string>
using namespace std;
// Function to generate and print binary sequences of length n
void generateBinarySequences(int n, string sequence = "") {
if (n == 0) {
cout << sequence << endl;
return;
} else {
generateBinarySequences(n - 1, sequence + "0");
generateBinarySequences(n - 1, sequence + "1");
}
}
int main() {
int n;
cout << "Enter the length of binary sequences (n): ";
cin >> n;
if (n < 0) {
cout << "Please enter a non-negative integer." << endl;
} else {
generateBinarySequences(n);
}
return 0;
}