牛客oj 习题3.3小白鼠排队&&习题3.5找最小数

结构体排序的两道送分题,无需多言。

#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;
}
发布了411 篇原创文章 · 获赞 72 · 访问量 16万+

猜你喜欢

转载自blog.csdn.net/Flynn_curry/article/details/104382635