Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5761 |

@blackshadows | 5715 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4944 |

@saiujwal13083 | 4506 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3516 |

@sushant_a | 3459 |

@verma_ji | 3341 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@aroranayan999 | 1115 |

@bt8816103042 | 739 |

@SherlockHolmes3 | 447 |

@codeantik | 441 |

@SHOAIBVIJAPURE | 430 |

@shalinibhataniya1097 | 408 |

@ShamaKhan1 | 392 |

@neverevergiveup | 381 |

@amrutakashikar2 | 355 |

@mahlawatep | 353 |

@murarry3625 | 352 |

Complete Leaderboard |

Implement different operations on a set s .

**Input:**

The first line of input contains an integer **T** denoting the no of test cases . Then T test cases follow. The first line of input contains an integer **Q** denoting the no of queries . Then in the next line are **Q** space separated queries .

A query can be of four types

1. a x (inserts an element x to the set s)

2. b (prints the contents of the set s)

3. c x (erases an element x from the set s)

4. d x (prints 1 if the element x is present in the set else print -1)

5. e (prints the size of the set s)

**Output:**

The output for each test case will be space separated integers denoting the results of each query .

**Constraints:**

1<=T<=100

1<=Q<=100

**Example:**

**Input**

2

6

a 1 a 2 a 3 b c 2 b

5

a 1 a 5 e d 5 d 2

**
Output**

1 2 3 1 3

2 1 -1

For the first test case

There are six queries. Queries are performed in this order

1. a 1 { insert 1 to set now set has {1} }

2. a 2 {inserts 2 to set now set has {1,2} }

3. a 3 {inserts 3 to set now set has {1,2,3} }

4. b {prints the set contents ie 1,2,3}

5. c 2 {removes 2 from the set }

6. b {prints the set contents ie 1,3}

There are five queries. Queries are performed in this order

1. a 1 {inserts 1 to set now set has {1} }

2. a 11 {inserts 11 to set now set has {1,11} }

3. e {prints the size of the set ie 2}

4. d 5 {since five is present prints 1}

5. d 2 {since 2 is not present in the set prints -1}

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
C++ STL | Set 6 (set)

...