/* VIM: let b:cf5build="clang -std=c++20 -O2 -pthread -lstdc++ -I. {SRC} -o {OUT}" VIM: let b:cf5run="{OUT}" */ #include #include #include #include /* Problem Description For given set of N elements print all possible subsets. Sample inputs - Expected outputs {"a"} -> <- empty set a {"a", "b"} -> <- empty set a b a b Input corner cases Empty input set yields to one empty subset. */ void printAllSubsets(const std::vector &inputSet, std::ostream &os) { std::vector subset(inputSet.size(), false); while (){ std::cout << '['; for (size_t i = 0; i < inputSet.size(); ++i){ if (subset[i]){ std::cout << inputSet[i] << ' '; } } std::cout << ']' << std::endl; std:: } std::vector } int main ( void ) {try{ auto begin = std::chrono::high_resolution_clock::now(); //...... const std::vector inputSet = {"a", "b", "c", "d"}; printAllSubsets(inputSet, std::cout); auto end = std::chrono::high_resolution_clock::now(); std::chrono::duration seconds = end - begin; std::cout << "Time: " << seconds.count() << std::endl; return 0; } catch ( const std::exception& e ) { std::cerr << std::endl << "std::exception(\"" << e.what() << "\")." << std::endl; return 2; } catch ( ... ) { std::cerr << std::endl << "unknown exception." << std::endl; return 1; }}