求助万能的谷民
  • 板块灌水区
  • 楼主sky_of_stars
  • 当前回复8
  • 已保存回复8
  • 发布时间2024/7/15 20:33
  • 上次更新2024/7/15 20:54:47
查看原帖
求助万能的谷民
772395
sky_of_stars楼主2024/7/15 20:33

萌新求助,帮忙看一下这份代码为什么会报错

#include <bits/stdc++.h>

using namespace std;
struct exp{
	int id;
	int A,B,C;
	int tot,totab,pos;
	bool operator <(const exp &o)const {
		return id<o.id;
	}
}a[10005];
int n;
int comp(exp x,exp y){
	if(x.tot!=y.tot){
		if(x.tot>y.tot)return 1;
		else return 0;
	}else{
		if(x.totab!=y.totab){
			if(x.totab>y.totab)return 1;
			else return 0;
		}else{
			return 5;
		}
	}
} 
int main(void){ 
	//freopen( "***.in", "r" , stdin);  
	//freopen( "***.out", "w" , stdout);
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> a[i].A >> a[i].B >> a[i].C;
		a[i].id=i;
		a[i].tot=a[i].A+a[i].B+a[i].C;
		a[i].totab=a[i].A+a[i].B;
		a[i].pos=i;
	}
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			int res=comp(a[i],a[j]);
			if(res==0){
				swap(a[i],a[j]);
			}else if(res==5){
				a[j].pos=a[i].pos;
			}
		}
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)cout << a[i].pos;
	return 0; 
} 

提示:不会就不要回复。

2024/7/15 20:33
加载中...