1938:【07NOIP普及组】奖学金

1938:【07NOIP普及组】奖学金

信息学奥赛一本通(C++版)在线评测系统

NOIP2007复赛 普及组 第一题

OpenJudge - 04:奖学金

P1093 [NOIP2007 普及组] 奖学金

[NOIP2007 普及组] 奖学金 - 洛谷




C++参考代码一:

#include<bits/stdc++.h>
using namespace std;
struct node
{
	int yu,sh,yi,id;
	int zf;
};
node t[1001];
bool cmp(node x,node y)
{
	if(x.zf>y.zf)
	{
		return 1;
	}
	else
	{
		if(x.zf<y.zf)
		{
			return 0;
		}
		else
		{
			if(x.yu>y.yu)
			{
				return 1;
			}
			else
			{
				if(x.yu<y.yu)
				{
					return 0;
				}
				else
				{
					return x.id<y.id;
				}
			}
		
		}
	}
}
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>t[i].yu>>t[i].sh>>t[i].yi;
		t[i].id=i;
		t[i].zf=t[i].yu+t[i].sh+t[i].yi;
	}
	sort(t+1,t+n+1,cmp);
	for(int i=1;i<=5;i++)
	{
		cout<<t[i].id<<' '<<t[i].zf<<endl;
	}
	return 0;
}


C++参考代码二:

#include <bits/stdc++.h>
using namespace std;
struct student
{
	int xuhao;
	int chinese;
	int math;
	int english;
	int total;
} s[500];


int cmp(const student& a,const student& b)
{
	if(a.total>b.total) return 1;
	if(a.total<b.total) return 0;
	
	if(a.chinese>b.chinese)  return 1;
	if(a.chinese<b.chinese)  return 0;
	
	if(a.xuhao < b.xuhao)  return 1;
	if(a.xuhao > b.xuhao)  return 0;	
}

int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;++i)
	{
		cin>>s[i].chinese>>s[i].math>>s[i].english;
		s[i].xuhao=i;
		s[i].total=s[i].chinese+s[i].math+s[i].english;
	}
	
	sort(s+1,s+n+1,cmp);
	
	for(int i=1;i<=5;++i)
	{
		cout<<s[i].xuhao<<" "<<s[i].total<<endl;
	}
	
	return 0;
}


C++参考代码三:

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int n,i,cmax=0,num;
struct s
{
    int c,m,e,total,num;
} a[301];
bool com(s a,s b)
{
    if(a.total!=b.total)
        return a.total>b.total;
    else
        if(a.c!=b.c)
            return a.c>b.c;
        else
            return a.num<b.num;
}
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
    {
	    a[i].num=i;
	    cin>>a[i].c>>a[i].m>>a[i].e;
	    a[i].total=a[i].c+a[i].m+a[i].e;
    }
    
	stable_sort(a+1,a+n+1,com);
	
    for(i=1;i<=5;i++)
    {
    cout<<a[i].num<<" "<<a[i].total<<endl;
    }
    
    return 0;
}




C++参考代码四:

#include<bits/stdc++.h>
using namespace std;
struct xx{
	int yw;
	int zf;
	int xh;
}xx[500];
int bj,flag;
void kp(int l,int r){
	bj=(l+r)/2;
	int m1=xx[(l+r)/2].zf,m2=xx[(l+r)/2].yw,m3=xx[(l+r)/2].xh,ll=l,rr=r;
	while(ll<rr){
		flag=0;
	while(ll!=rr){
		if(xx[ll].zf>m1){
			break;
		}
		if(xx[ll].zf==m1&&xx[ll].yw>m2){
			break;
		}
		if(xx[ll].zf==m1&&xx[ll].yw==m2&&xx[ll].xh<m3){
			break;
		}
		if(xx[ll].zf==m1&&xx[ll].yw==m2&&xx[ll].xh==m3){
			flag=1;
			bj=ll;
			break;
		}
		ll++;
	}
	while(ll!=rr){
		if(xx[rr].zf<m1){
			break;
		}
		if(xx[rr].zf==m1&&xx[rr].yw<m2){
			break;
		}
		if(xx[rr].zf==m1&&xx[rr].yw==m2&&xx[rr].xh>m3){
			break;
		}
		if(xx[rr].zf==m1&&xx[rr].yw==m2&&xx[rr].xh==m3){
			flag=2;
			bj=rr;
			break;
		}
		rr--;
	}
	if(ll==rr){
		xx[bj].xh=xx[ll].xh;
		xx[bj].yw=xx[ll].yw;
		xx[bj].zf=xx[ll].zf;
		xx[ll].xh=m3;
		xx[ll].yw=m2;
		xx[ll].zf=m1;
		rr--;
		ll++;
		break;
	}
	if(flag==1){
		bj=rr;
	}
	if(flag==2){
		bj=ll;
	}
	int t=xx[rr].zf;
	xx[rr].zf=xx[ll].zf;
	xx[ll].zf=t;
	t=xx[rr].xh;
	xx[rr].xh=xx[ll].xh;
	xx[ll].xh=t;
	t=xx[rr].yw;
	xx[rr].yw=xx[ll].yw;
	xx[ll].yw=t;
	}
	if(rr>l) kp(l,rr);
	if(ll<r) kp(ll,r);
}
int main(){
	int n,c,d,w;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>xx[i].yw>>c>>d;
		xx[i].xh=i;
		xx[i].zf=xx[i].yw+c+d;
	}
	kp(1,n);
	for(int i=n;i>n-5;i--){
		cout<<xx[i].xh<<" "<<xx[i].zf<<endl;
	}
}




C++参考代码五:

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
using namespace std;
int a[301],b[301],c[301],y,s,i,j,n;
int main()
{
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>c[i]>>s>>y;  //  c[i]语文    s:数学  y:英语   
		a[i]=c[i]+s+y;  //求出当前同学的总成绩
		b[i]=i;    //b[i]:学号 
	}
	for(i=1;i<=n;i++)   //选择排序 
	for(j=i;j<=n;j++)
	{
		if(a[i]<a[j])     //总分的排序:从大到小   10<30 
		{
			swap(a[i],a[j]);
			swap(b[i],b[j]);
			swap(c[i],c[j]);
		}
		if(a[i]==a[j] && c[i]<c[j])
		{
			swap(a[i],a[j]);
			swap(b[i],b[j]);
			swap(c[i],c[j]);
		}
		
		if(a[i]==a[j] && c[i]==c[j] && b[i]>b[j])   
		{
			swap(a[i],a[j]);
			swap(b[i],b[j]);
			swap(c[i],c[j]);
		}
		
	 } 
	 
	 for(i=1;i<=5;i++)
	 {
	 	cout<<b[i]<<' '<<a[i]<<endl;
	 }
	 
	 return 0;
	
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dllglvzhenfeng

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值