1062 Talent and Virtue (25 point(s))

本文通过一个C++程序实例,演示了如何使用结构体和自定义比较函数进行复杂数据排序,同时介绍了基于条件的计数和度量标准设置。代码中详细展示了如何根据多个条件对数据进行排序,包括ID、度量标准以及特定数值组合。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

matter

1.小毛病太多了,真的一时半会儿错了都不知道哪里错了,语法有错,然后代码也要写错,半天根本看不出来问题出在哪里。

2.掌握cmp的标准写法。

code

#include<iostream>
#include<algorithm>
using namespace std;

struct node{
	int id , d , c , degree;
}Node[100005];


bool cmp(node a , node b){
	if(a.degree == b.degree){
		if(a.c + a.d == b.c + b.d){
			if(a.d == b.d){
				return a.id < b.id;
			}
	    	else{
				return a.d > b.d;
			}
		}
		else{
			return a.d + a.c > b.d + b.c;
		}
	}
	else{
		return a.degree < b.degree;
	}
} 

int main(){
	int N , L , H , num = 0;
	scanf("%d %d %d" , &N , &L , &H);
	for(int i = 0 ; i < N ; i ++){
		scanf("%d %d %d" , &Node[i].id , &Node[i].d , &Node[i].c);
		
		//judge the degree
		if(Node[i].c >= L && Node[i].d >= L){
			num ++;
			if(Node[i].d >= H && Node[i].c >= H){
				Node[i].degree = 1;	//	degree 1 
			}			
			else if(Node[i].d >= H && Node[i].c < H){
				Node[i].degree = 2;// degree 2
			}
			else if(Node[i].d < H && Node[i].c < H && Node[i].d >= Node[i].c){
				Node[i].degree = 3;// degree 3
			}	
			else{
				Node[i].degree = 4;// degree 4
			}
		}
		else{
			Node[i].degree = 5;
		}
	}

	//get the result
	printf("%d\n" , num);
	sort(Node , Node + N, cmp);
	
	for(int i = 0 ; i < num ; i ++){
		printf("%d %d %d" , Node[i].id , Node[i].d , Node[i].c);
		if(i != num - 1)	printf("\n");
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值