Pair to group:
Pair is equivalent to a structure with two elements
Call header file:
#include <algorithm>
using namespace Std;
Detailed usage (part):
pair<string, double> p2------P2 has two types, the first element is string, and the second element is double
P2 = Make_pair ("AA", 5.0)------for P2 assignment
Pair<string, double> p3 (p2)------pair Copy
P2.first------Access the first element in pair
P2.second------Access to the second element in pair
Sort:
BOOL Comp (pair<int, int> A, pair<int, int> b)
{ ...... }
If there is no write-sort function, the first element is sorted by default, if the same is sorted by the second element (small to large)
#include <stdio.h>
#include <algorithm>
using namespace std;
Pair<int, int> p[15];
BOOL Comp (pair<int, int> A, pair<int, int> b)
{
if (A.first>b.first | | A.first==b.first & & A.second>b.second) return
1;
return 0;
}
int main (void)
{
int i, j, k = 0;
for (i=3;i>=1;i--)
{
for (j=1;j<=4;j++)
p[++k] = Make_pair (i, j);
}
Sort (p+1, p+k+1);
for (i=1;i<=k;i++)
printf ("%d%d\n", P[i].first, P[i].second);
printf ("\ n");
Sort (p+1, p+k+1, comp);
for (i=1;i<=k;i++)
printf ("%d%d\n", P[i].first, P[i].second);
return 0;
}