跳到正文

个人记录

2.2日测试总结

齐芒约 1 分钟
原文
文章信息与版本

文章信息

发布
2024年2月2日
收录
2025年12月12日
更新
2026年11月13日
篇幅
约 1 分钟
获赞
2

版本

  1. v1当前

总结

T1 P5740

错误代码

C++
#include <bits/stdc++.h>
using namespace std;
struct stu
{
	string name;
	int ying;
	int shu;
	int yu;
	int id;
}s[100000];
bool smp(stu a,stu b)
{
	if(a.shu+a.ying+a.yu==b.shu+b.ying+b.yu)
	{
		if(a.id<b.id)
		{
			return 1;
		}
		if(a.id>b.id)
		{
			return 0;
		}		
	}
	if(a.shu+a.ying+a.yu>b.shu+b.ying+b.yu)
	{
		return 1;	
	}
	else
	{
		return 0;	
	}	
}
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;++i)
	{
		cin>>s[i].name>>s[i].yu>>s[i].shu>>s[i].ying;	
		s[i].id = i;
	}
	sort(s+1,s+n+1,smp);
	cout<<s[1].name<<' '<<s[1].yu<<' '<<s[1].shu<<' '<<s[1].ying;
	return 0;	
} 

错误原因

粘贴你的错误代码

C++
for(int i=1;i<=n;++i)
{
	cin>>s[i].name>>s[i].yu>>s[i].shu>>s[i].ying;	
	忘记写id了
}