Pair ! Basics!

main.cpp
main.cpp
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long 
 
int main() 
{ 
    pair<int,int>px,py; 
        //created 2 pairs,px and py 
    pair <int,int>p1(23,42); 
        //p1 pair is created initializing its value 2 23,42    
    pair<int,int>p2=pair<int,int>(234,534); 
        //can also initialize in this way 
    px=p1; 
        //assigned p1 value in px 
    py.first=p2.first*px.second; 
    py.second=p2.second*px.first; 
        //use of pair.first/pair.second 
    cout<<"py :( "<<py.first<<" , "<<py.second<<" )\n"; 
    pair< pair<int,int>,pair<int,int> >p3; 
    p3=pair<pair<int,int>,pair<int,int>>(px,py); 
    cout<<"p3: (("; 
    cout<<p3.first.first<<" , "<<p3.first.second<<"),( "<<p3.second.first<<" , "<<p3.second.second<<" ) )"<<endl; 
 
        //using make_pair 
    pair<double,pair<string,int>>p4; 
    p4=make_pair(3.14159,make_pair("pi",5)); 
    cout<<"This is "<<p4.second.first<<", Vlue: "<<p4.first<<" precision: "<<p4.second.second<<" digits\n"; 
}

মন্তব্যসমূহ

এই ব্লগটি থেকে জনপ্রিয় পোস্টগুলি

CP3 Exercise 1.2.3//5

C++ Class

SPOJ-INVERSE-SORT