I have a series of Key value pairs. Each Key has 2 values. Values of Keys ma coincide.
Initially i start with Key1, ValueKey1, ValueKey2 are stored in a set.(Maybe Array).

Now for each consecutive Keyi, i check if Valuei, Valuei+1 are in the set. If any one of them is in the set, then join the set.

Else if both KeyValues are present in a set, discard that key .

How can i implement this thing using C++, i have very less idea, so i would suggest if possible a code snippet or a hint would be really helpful.

Thanks

I have a series of Key value pairs. Each Key has 2 values. Values of Keys ma coincide.
Initially i start with Key1, ValueKey1, ValueKey2 are stored in a set.(Maybe Array).

Now for each consecutive Keyi, i check if Valuei, Valuei+1 are in the set. If any one of them is in the set, then join the set.

Else if both KeyValues are present in a set, discard that key .

How can i implement this thing using C++, i have very less idea, so i would suggest if possible a code snippet or a hint would be really helpful.

Thanks

Any help? Is it way too difficult ? :(

I don't get it. So you say you have a series of key value pairs with 2 values per key, something like this: key => [value1, value2]. Then you loop thru the keys, looking if value1 or value2 of that key are in some set; what set would that be?

I don't get it. So you say you have a series of key value pairs with 2 values per key, something like this: key => [value1, value2]. Then you loop thru the keys, looking if value1 or value2 of that key are in some set; what set would that be?

The problem exactly is.I have an array of numbers.
For any element in the array when i run a function it gives me two values(int).

Now for each element in the array if bot the corresponding values are present in the set we discard it, else if we have one value we add that array element to our solution. else if we have no match found among the two, we make another new set.

Now if we read another array element we check its entry in both the sets created.. and so on...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.