I'm not sure to understand your question... What do you want to achieve exactly? As I understand, you want to create a "mapping" from some integer-sets upon Strings? I think that's not possible "directly" with C++'s sets. However, I would suggest to use a map instead of a set -- a map, which maps sets upon strings. Something like (untested...):
#include <set> #include <map> #include <string> #include <cstdarg> std::set<int> Generate(int N, ...){ // Helperfunction to provide an easy way to generate the sets va_list ap; std::set<int> s; va_start(ap, N); for(int i=0; i<N; i++) s.insert(va_arg(ap, int)); va_end(ap); return s; } typedef std::set<int> s_t; typedef std::map<s_t, std::string> map_t; map_t the_map; the_map[Generate(4,2,3,6,12)] = "A"; the_map[Generate(4,2,3,4,12)] = "B"; the_map[Generate(4,4,7,10,14)] = "2212"; the_map[Generate(3,5,13,14)] = "3434"; Then, you can use map's interface to access all subset -> key relations. If you want to verify whether a set is a subset, just use "includes" like std::includes (s1.begin(),s1.end(), s2.begin(), s2.end()); So may be you need some more complex structure, combining: a) a set "s2" which contains all elements. Then, you can use "includes" to determine whether a given list of integers really is a subset of s2 or not b) a map as std::map<s_t, std::string> in order to store the mapping between subsets -> keys. HTH, Axel On Sat, May 14, 2011 at 5:18 AM, vivek dhiman <vivek4dhi...@gmail.com>wrote: > Ok so if i have to match subsets of a set to a particular key how to do > that? > > like if the set is { 2,3,4,5,6,7,10,12,13,14 } > > > {2,3,6,12} --- A > {2,3,4,12} --- B > {4,7,10,14} --- 2212 > {5,13,14} --- 3434 > > > How to implement such type of sets in C/C++ ?? > > > > > On Sat, May 14, 2011 at 5:32 AM, Carlos Guia <zyx3d...@gmail.com> wrote: > >> If you mean how are they implemented, the standard doesn't not specify how >> it has to be done, just some complexity restrictions are imposed. However, >> most implementations use some kind of binary tree and specifically Microsoft >> Visual Studio's implementation uses red-black trees. >> >> Carlos Guía >> >> >> On Fri, May 13, 2011 at 2:40 PM, vivek dhiman <vivek4dhi...@gmail.com>wrote: >> >>> i meant how sets behave ? >>> >>> -- >>> >> -- You received this message because you are subscribed to the Google Groups "google-codejam" group. To post to this group, send email to google-code@googlegroups.com. To unsubscribe from this group, send email to google-code+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-code?hl=en.