/* function for appending a char to a char array */
void append(char* s, char c) {
// comparator function for qsort in c
int cmpfunc (const void * a, const void * b) {
return ( *(char*)a - *(char*)b );
// Below function extracts characters present in src
// between m and n (excluding n)
char* substr(const char *src, int m, int n)
// get length of the destination string
// allocate (len + 1) chars for destination (+1 for extra null character)
char *dest = (char*)malloc(sizeof(char) * (len + 1));
// extracts characters between m'th and n'th index from source string
// and copy them into the destination string
for (int i = m; i < n && (*(src + i) != '\0'); i++)
// null-terminate the destination string
// return the destination string
void powerSet(char *s, char *cur, int index){
for(int i = index + 1; i<n; i++){
/* creating a temporary char array */
/* copying original char array to temp array */
/* append char s[i] to char array temp */
/*append char s[i] to cur */
/* After all subset beginning with "cur" are printed,
we will remove the last character to consider different
cur = substr(cur, 0, strlen(cur) - 1);
char str[100]; scanf("%s" ,str);
//sorting all the characters of str in
qsort(str, strlen(str), sizeof(char), cmpfunc);
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/* function for appending a char to a char array */
void append(char* s, char c) {
int len = strlen(s);
s[len] = c;
s[len+1] = '\0';
}
// comparator function for qsort in c
int cmpfunc (const void * a, const void * b) {
return ( *(char*)a - *(char*)b );
}
// Below function extracts characters present in src
// between m and n (excluding n)
char* substr(const char *src, int m, int n)
{
// get length of the destination string
int len = n - m;
// allocate (len + 1) chars for destination (+1 for extra null character)
char *dest = (char*)malloc(sizeof(char) * (len + 1));
// extracts characters between m'th and n'th index from source string
// and copy them into the destination string
for (int i = m; i < n && (*(src + i) != '\0'); i++)
{
*dest = *(src + i);
dest++;
}
// null-terminate the destination string
*dest = '\0';
// return the destination string
return dest - len;
}
void powerSet(char *s, char *cur, int index){
int n = strlen(s);
if(index == n)
return ;
printf("%s\n", cur);
for(int i = index + 1; i<n; i++){
/* creating a temporary char array */
char temp[100];
/* copying original char array to temp array */
strcpy(temp, cur);
/* append char s[i] to char array temp */
append(temp, s[i]);
/*append char s[i] to cur */
append(cur, s[i]);
powerSet(s, temp, i);
/* After all subset beginning with "cur" are printed,
we will remove the last character to consider different
prefix of subsets */
cur = substr(cur, 0, strlen(cur) - 1);
}
}
int main()
{
char str[100]; scanf("%s" ,str);
//sorting all the characters of str in
//non-decreasing order
qsort(str, strlen(str), sizeof(char), cmpfunc);
char res[100] = "";
powerSet(str, res, -1);
return 0;
}
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/* function for appending a char to a char array */
void append(char* s, char c) {
int len = strlen(s);
s[len] = c;
s[len+1] = '\0';
}
// comparator function for qsort in c
int cmpfunc (const void * a, const void * b) {
return ( *(char*)a - *(char*)b );
}
// Below function extracts characters present in src
// between m and n (excluding n)
char* substr(const char *src, int m, int n)
{
// get length of the destination string
int len = n - m;
// allocate (len + 1) chars for destination (+1 for extra null character)
char *dest = (char*)malloc(sizeof(char) * (len + 1));
// extracts characters between m'th and n'th index from source string
// and copy them into the destination string
for (int i = m; i < n && (*(src + i) != '\0'); i++)
{
*dest = *(src + i);
dest++;
}
// null-terminate the destination string
*dest = '\0';
// return the destination string
return dest - len;
}
void powerSet(char *s, char *cur, int index){
int n = strlen(s);
if(index == n)
return ;
printf("%s\n", cur);
for(int i = index + 1; i<n; i++){
/* creating a temporary char array */
char temp[100];
/* copying original char array to temp array */
strcpy(temp, cur);
/* append char s[i] to char array temp */
append(temp, s[i]);
/*append char s[i] to cur */
append(cur, s[i]);
powerSet(s, temp, i);
/* After all subset beginning with "cur" are printed,
we will remove the last character to consider different
prefix of subsets */
cur = substr(cur, 0, strlen(cur) - 1);
}
}
int main()
{
char str[100]; scanf("%s" ,str);
//sorting all the characters of str in
//non-decreasing order
qsort(str, strlen(str), sizeof(char), cmpfunc);
char res[100] = "";
powerSet(str, res, -1);
return 0;
}
void powerSet(string s,string cur = "",int index = -1){
for(int i = index+1; i<n; i++){
/* After all subset beginning with "cur" are printed,
we will remove the last character to consider different
cur = cur.erase(cur.size()-1);
sort(str.begin(),str.end());
#include <bits/stdc++.h>
using namespace std;
void powerSet(string s,string cur = "",int index = -1){
int n = s.size();
if(index == n)
return ;
cout<<cur<<"\n";
for(int i = index+1; i<n; i++){
cur += s[i];
powerSet(s,cur,i);
/* After all subset beginning with "cur" are printed,
we will remove the last character to consider different
prefix of subsets */
cur = cur.erase(cur.size()-1);
}
}
int main()
{
string str;cin>>str;
sort(str.begin(),str.end());
powerSet(str);
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void powerSet(string s,string cur = "",int index = -1){
int n = s.size();
if(index == n)
return ;
cout<<cur<<"\n";
for(int i = index+1; i<n; i++){
cur += s[i];
powerSet(s,cur,i);
/* After all subset beginning with "cur" are printed,
we will remove the last character to consider different
prefix of subsets */
cur = cur.erase(cur.size()-1);
}
}
int main()
{
string str;cin>>str;
sort(str.begin(),str.end());
powerSet(str);
return 0;
}
//Function of sorting a string
public static String sortString(String inputString){
// convert input string to char array
char tempArray[] = inputString.toCharArray();
// return new sorted string
return new String(tempArray);
static void powerSet(String s,String cur,int index){
for(int i = index+1; i<n; i++){
/* After all subset beginning with "cur" are printed,
we will remove the last character to consider different
cur = cur.substring(0, cur.length() - 1);
public static void main(String args[]) throws IOException {
Scanner sc = new Scanner(System.in);
import java.util.*;
import java.io.*;
public class Main {
//Function of sorting a string
public static String sortString(String inputString){
// convert input string to char array
char tempArray[] = inputString.toCharArray();
// sort tempArray
Arrays.sort(tempArray);
// return new sorted string
return new String(tempArray);
}
static void powerSet(String s,String cur,int index){
int n = s.length();
if(index == n)
return ;
System.out.println(cur);
for(int i = index+1; i<n; i++){
cur += s.charAt(i);
/* After all subset beginning with "cur" are printed,
we will remove the last character to consider different
prefix of subsets */
powerSet(s,cur,i);
cur = cur.substring(0, cur.length() - 1);
}
}
public static void main(String args[]) throws IOException {
Scanner sc = new Scanner(System.in);
String str = sc.next();
str = sortString(str);
String cur = "";
int index = -1;
powerSet(str,cur,index);
}
}
import java.util.*;
import java.io.*;
public class Main {
//Function of sorting a string
public static String sortString(String inputString){
// convert input string to char array
char tempArray[] = inputString.toCharArray();
// sort tempArray
Arrays.sort(tempArray);
// return new sorted string
return new String(tempArray);
}
static void powerSet(String s,String cur,int index){
int n = s.length();
if(index == n)
return ;
System.out.println(cur);
for(int i = index+1; i<n; i++){
cur += s.charAt(i);
/* After all subset beginning with "cur" are printed,
we will remove the last character to consider different
prefix of subsets */
powerSet(s,cur,i);
cur = cur.substring(0, cur.length() - 1);
}
}
public static void main(String args[]) throws IOException {
Scanner sc = new Scanner(System.in);
String str = sc.next();
str = sortString(str);
String cur = "";
int index = -1;
powerSet(str,cur,index);
}
}
def powerSet(s, cur = "", index = -1):
for i in range(index + 1, n):
def powerSet(s, cur = "", index = -1):
n = len(s)
if(index == n):
return
print(cur)
for i in range(index + 1, n):
cur = cur + s[i]
powerSet(s,cur,i)
cur = cur[:len(cur)-1]
s = list(input())
s.sort()
powerSet(s)
def powerSet(s, cur = "", index = -1):
n = len(s)
if(index == n):
return
print(cur)
for i in range(index + 1, n):
cur = cur + s[i]
powerSet(s,cur,i)
cur = cur[:len(cur)-1]
s = list(input())
s.sort()
powerSet(s)