原题:https://www.acwing.com/problem/content/4675/ 我的代码
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1005;
struct cloth{
string color;
int d, id;
int a;
}c[N];
bool cmp1(cloth x, cloth y)
{
if(x.color == y.color)return x.id < y.id;
return x.color < y.color;
}
bool cmp2(cloth x, cloth y)
{
if(x.d == y.d)return x.id < y.id;
return x.d < y.d;
}
int A[N], B[N];
int main()
{
int t;
scanf("%d", &t);
for(int cases = 1; cases <= t; ++ cases)
{
int n;
scanf("%d", &n);
for(int i = 1; i <= n; ++ i)
{
scanf("%s %d %d", &c[i].color, &c[i].d, &c[i].id);
c[i].a = i;
}
sort(c + 1, c + n + 1, cmp1);
for(int i = 1; i <= n; ++ i)
{
A[i] = c[i].a;
}
sort(c + 1, c + n + 1, cmp2);
for(int i = 1; i <= n; ++ i){
B[i] = c[i].a;
}
int res = 0;
for(int i = 1; i <= n; ++ i)
if(A[i] == B[i])++ res;
printf("Case #%d:%d\n", cases, res);
}
return 0;
}