Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <cstdio>
- using namespace std;
- typedef pair<int, int> pereche;
- vector< pereche > v;
- /// Ordine crescatoare dupa primul camp si
- /// descrescatoare dupa al II-lea camp
- bool comparator( pereche A, pereche B )
- {
- if( A.first == B.first )
- return A.second > B.second;
- return A.first < B.first;
- }
- void afiseaza()
- {
- for( int i = 0; i < v.size(); ++i )
- cout << "(" << v[i].first << ", " << v[i].second << ") ";
- cout << endl << endl;
- }
- int citeste_rapid_pozitiv()
- {
- int s = 0;
- char lit;
- while( (lit = getchar()) && lit >= '0' && lit <='9' )
- {
- s = ( s << 1 ) + ( s << 3 ) + (lit-'0');
- }
- return s;
- }
- int main()
- {
- int n, i, a, b;
- ios::sync_with_stdio( false );
- cin.tie();
- n = citeste_rapid_pozitiv();
- cout << "Am citit rapid: " << n << endl;
- for( i = 0; i < n; ++i )
- {
- a = citeste_rapid_pozitiv();
- b = citeste_rapid_pozitiv();
- //pereche ceva;
- //ceva = make_pair( a, b );
- //v.push_back( ceva );
- v.push_back( make_pair(a, b) );
- }
- afiseaza();
- sort( v.begin(), v.end(), comparator );
- afiseaza();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement