Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // In The Name Of Allah
- #include<bits/stdc++.h>
- #include<string.h>
- using namespace std;
- int main()
- {
- //Pair has two value and two data type
- //Pair Declare :
- pair <string , int >p;
- p.first = "imran";
- p.second = 12;
- cout << p.first << " " << p.second << endl;//Output: imran 12
- //User Input :
- pair <string , int >p;
- cin >> p.first >> p.second;
- cout << p.first << " " << p.second;
- //Make pair using make_pair function :
- pair<int , int>p;
- p = make_pair(15,19);
- cout << p.first << " " << p.second << endl;//output 15 19
- p.second++;//Increasing
- cout << p.first << " " << p.second << endl;//output 15 20
- //Making pair without make_pair :
- pair<string ,vector<int> >p;
- p = {"Imran" , {1,2,3,4,5} };
- cout << p.first << " " << p.second.size() << endl;//Imran 5
- //Compare Pair :Fist value check
- //if first value equal then compare second value
- pair < int , int> p1,p2;
- p1 = {2,5};
- p2 = {3,1};
- if(p1 < p2)cout <<"Yes" << endl;//Yes
- //Minimum or Maximum pair :
- pair < int, int>p1,p2;
- p1 = {3,5};
- p2 = {1,9};
- pair<int, int>p= max(p1,p2);
- cout << p.first << " " << p.second << endl;//3 5
- //Sorting Vector Of pair:
- vector< pair<int, int> >v;
- v.push_back( {6,5} );
- v.push_back( {2,3} );
- v.push_back( {4,5} );
- v.push_back( {6,1} );
- v.push_back( {1,9} );
- sort(v.begin() , v.end());
- for(auto u:v)cout <<u.first << " " << u.second << endl;
- /*1 9
- 2 3
- 4 5
- 6 1
- 6 5*/
- //Sorting pair of array:
- pair<int , int> p[ ] = { {6,5}, {2,3}, {4,5}, {6,1}, {1,9} };
- sort(p, p+5);
- for(int i=0; i<5; i++){
- cout << p[i].first << " " << p[i].second << endl;
- }
- /*1 9
- 2 3
- 4 5
- 6 1
- 6 5*/
- //Unique Vector of pair:
- vector< pair< string , int> >v;
- v.push_back( {"shariar" , 21} );
- v.push_back( {"momo" , 13} );
- v.push_back( {"sharif" , 34} );
- v.push_back( {"shariar" , 35} );
- v.push_back( {"sharif" , 34} );
- v.push_back( {"shariar" , 21} );
- v.push_back( {"momo" , 13} );
- sort(v.begin(), v.end());
- int sz = unique(v.begin(), v.end())- v.begin();
- for(int i=0; i<sz; i++){
- cout << v[i].first << " " << v[i].second << endl;
- }
- /*momo 13
- shariar 21
- shariar 35
- sharif 34*/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement