Searching SER14

QUESTION DESCRIPTION 

You are given n triangles.

You are required to find how many triangles are unique out of given triangles. For each triangle you are given three integers a,b,c , the sides of a triangle.

A triangle is said to be unique if there is no other triangle with same set of sides.

Note : It is always possible to form triangle with given sides.

INPUT:

First line contains n, the number of triangles. Each of next n lines contain three integers a,b,c (sides of a triangle).

Output:

print single integer, the number of unique triangles.



TEST CASE 1 

INPUT
5
7 6 5
5 7 6
8 2 9
2 3 4
2 4 3
OUTPUT
1

TEST CASE 2 

INPUT
4
1574 5033 3460
3329 9634 6306
3460 1574 5033
7719 13529 5811
OUTPUT
2

using c++




//I_F_A
#include "bits/stdc++.h"
using namespace std;

map< pair<long long,pair<long long,long long> > ,long long> mymap;

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    long long n;
    cin >> n;
    
    while(n--){
        
        long long arr[3];
        cin >> arr[0] >> arr[1] >> arr[2];
        
        sort(arr,arr+3);
        
        pair<long long,pair<long long,long long> > temp;
        temp.first = arr[0];
        temp.second.first = arr[1];
        temp.second.second = arr[2];
        
        mymap[temp]++;
    }
    
    long long ans = 0;
    for(map< pair<long long,pair<long long,long long> > ,long long>::iterator it = mymap.begin() ; it != mymap.end() ; it++){
        
        pair<long long,pair<long long,long long> > temp = it->first;
        long long count1 = it->second;
        
        if(count1 == 1)
        {
            ans++;
        }
    }
    cout << ans << endl;
}

Comments

Popular Posts