How to check two points are equal using C++ STL?
Input :
0, 0
0, 0
Output :
Yes
How to check two points are equal using C++ STL?
Input :
0, 0
0, 0
Output :
Yes
Why you want this question from STL? It can simply be perform by if-else condition.
I tried to implement this code :
But here No STL are used. Only if else are used
But how???
Suppose you have two points as pair<int,int> .
p1,p2 are the two points,then you write
cout<<((p1==p2)?“YES”:“NO”);
Remember to enclose (p1==p2)?“YES”:“NO” in parentheses as conditional operator have least precedence.
So cout<<((p1==p2)?“YES”:“NO”); can get your job done.
Hope it helps…
Vector V[0] represent a pair inside Vector, so V[0].first represent the first element and V[0].second represent the second element of V[0]. Same case are applying on V[1]. So i compare condition you are just comparing both these value of vector- (V[0], V[1]) by simply if condition.
As pointed out by others, you don’t need to use STL here. Normal comparison operation will do.
But since you ask specifically for using C++ STL, refer to http://www.cplusplus.com/reference/functional/equal_to/
Declare an object of equal_to of appropriate type (pair< int, int > here). Let it be f. Just call f(V[0], V[1]).
Here is an example - http://ideone.com/TlXFZG