Search
 
SCRIPT & CODE EXAMPLE
 

CPP

print all subsequences

#include<bits/stdc++.h>
using namespace std;
vector<string> AllPossibleStrings(string s) {
	int n = s.length();
	vector<string>ans;
	for (int num = 0; num < (1 << n); num++) {
		string sub = "";
		for (int i = 0; i < n; i++) {
			//check if the ith bit is set or not
			if (num & (1 << i)) {
				sub += s[i];
			}
		}
		if (sub.length() > 0) {
			ans.push_back(sub);
		}
	}
	sort(ans.begin(), ans.end());
	return ans;
}
int main()
{


	string s="abc";
	vector<string>ans = AllPossibleStrings(s);
	//printint all the subsequence.
	cout<<"All possible subsequences are "<<endl;
	for (auto it : ans) {
		cout << it << " ";
	}

}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ comment 
Cpp :: operator overloading c++ 
Cpp :: bubble sort function in c++ 
Cpp :: cpp compiler online 
Cpp :: char at in c++ 
Cpp :: c++ string example 
Cpp :: 83. remove duplicates from sorted list solution in c++ 
Cpp :: . The cout with the insertion operator (<<) is used to print a statement 
Cpp :: front priority queue cpp 
Cpp :: cpp serial print override always in same place 
Cpp :: how atan work c++ 
Cpp :: c++ string replace 
Cpp :: Madiar loh 
Cpp :: code runner c++ syntax error 
Cpp :: idnefier endl in undefince 
Cpp :: fabs c c++ 
Cpp :: sfml disable message 
Cpp :: ++m in c 
Cpp :: sort an array using stl 
Cpp :: pointers mcq sanfoundry 
Cpp :: C++ Join thread 
Cpp :: zsh: segmentation fault ./provided_files.exe erosion X . 
Cpp :: Nested ternary operator C++ 
Cpp :: delete[] cpp 
Cpp :: c++ enter name and surname one string 
Cpp :: enqueue function with linked list implementation in c++ 
Cpp :: c++ thread id 
Cpp :: txt auslesen c++ 
Cpp :: convert string to wide string 
Cpp :: algorithm map values 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =