Count number of unique Triangles using STL | Set 1 (Using set)
We are given n triangles along with length of their three sides as a,b,c. Now we need to count number of unique triangles out of these n given triangles. Two triangles are different from one another if they have at least one of the sides different.
Example:
Input: arr[] = {{1, 2, 2}, {4, 5, 6}, {4, 5, 6} Output: 2 Input: arr[] = {{4, 5, 6}, {6, 5, 4}, {1, 2, 2}, {8, 9, 12} Output: 3
We strongly recommend you to minimize your browser and try this yourself first.
Since we are asked to find number of “unique” triangles, we can use either set or unordered_set. In this post, set based approach is discussed.
How to store three sides as an element in the container? We use STL pair to store all the three sides together as
