排序
2026-11-22 15:11:50
发布于:广东
1阅读
0回复
0点赞
冒泡排序+结构体
#include<bits/stdc++.h>
using namespace std;
struct stu{
int h;
int w;
}st[3010];
bool cmp(stu x,stu y){
if(x.h != y.h) return x.h<y.h;
else if(x.w != y.w) return x.w<y.w;
}
int main(){
int n;
cin>>n;
int ans=0;
for(int i=1;i <= n;i++)
{
cin>>st[i].h>>st[i].w;
}
for(int i=1;i <= n;i++){
for(int j=2;j <= n;j++){
if(cmp(st[j-1],st[j])){
swap(st[j-1],st[j]);
ans++;
}
}
}
cout << ans;
}
这里空空如也






有帮助,赞一个