结构体排序的两道送分题,无需多言。
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <cmath>
#include <climits>
using namespace std;
const int MAXN = 105;
const int INF = INT_MAX;
struct Mouse{
int weight;
string color;
};
Mouse mouse[MAXN];
bool cmp(Mouse x, Mouse y){
return x.weight > y.weight;
}
int main(){
// freopen("in.txt", "r", stdin);
int N;
while(~scanf("%d", &N)){
for(int i = 0; i < N; i++){
cin >> mouse[i].weight >> mouse[i].color;
}
sort(mouse, mouse+N, cmp);
for(int i = 0; i < N; i++){
cout << mouse[i].color << endl;
}
}
return 0;
}
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <cmath>
#include <climits>
using namespace std;
const int MAXN = 1005;
const int INF = INT_MAX;
struct Node{
int a;
int b;
};
Node node[MAXN];
bool cmp(Node x, Node y){
if(x.a == y.a) return x.b < y.b;
return x.a < y.a;
}
int main(){
// freopen("in.txt", "r", stdin);
int n;
while(~scanf("%d", &n)){
for(int i = 0; i < n; i++){
scanf("%d %d", &node[i].a, &node[i].b);
}
sort(node, node+n, cmp);
printf("%d %d\n", node[0].a, node[0].b);
}
return 0;
}