- 奖学金
- 2015-10-17 16:12:10 @
var
xue,yu,zong:array[1..300] of integer;
i,j,n,a,b,c,s:integer;
begin
readln(n);
for i:=1 to n do
begin
readln(a,b,c);
xue[i]:=i;
yu[i]:=a;
zong[i]:=a+b+c;
end;
for i:=1 to n-1 do;
for j:=i+1 to n do
begin
if (zong[i]>zong[j])or ((zong[i]=zong[j]) and (yu[i]>yu[j]))or ((zong[i]=zong[j])and (yu[i]=yu[j])and(xue[i]>xue[j])) then
begin
s:=zong[i]; zong[i]:=zong[j]; zong[j]:=s;
s:=xue[i];xue[i]:=xue[j];xue[j]:=xue[i];
s:=yu[i];yu[i]:=yu[j];yu[j]:=s;
end;
end;
for i:=1 to 5 do
writeln(xue[i],' ',zong[i]);
end.
3 条评论
-
sslz-yq LV 5 @ 2016-07-15 11:08:45
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=300+5;
struct Stu
{
int x,y,z;
int id,sum_score;
}a[maxn];
int cmp(Stu a,Stu b)
{
if(a.sum_score!=b.sum_score)
return a.sum_score>b.sum_score;
if(a.x!=b.x)
return a.x>b.x;
return a.id<b.id;
}
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i].x;
cin>>a[i].y;
cin>>a[i].z;
a[i].sum_score=a[i].x+a[i].z+a[i].y;
a[i].id=i;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=5;i++)
printf("%d %d\n",a[i].id,a[i].sum_score);
return 0;
} -
2015-10-20 22:46:49@
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
struct point {
int a,b,c,pos,sum;
}per[310];
bool cmp(point x,point y)
{
if(x.sum!=y.sum)
return x.sum>y.sum;
if(x.a!=y.a)
return x.a>y.a;
return x.pos<y.pos;
}
int main()
{
//freopen("","r",stdin);
//freopen("","w",stdout);
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d%d%d",&per[i].a,&per[i].b,&per[i].c);
per[i].pos=i;
per[i].sum=per[i].a+per[i].b+per[i].c;
}
sort(per+1,per+n+1,cmp);
for(int i=1;i<=5;i++)printf("%d %d\n",per[i].pos,per[i].sum);
return 0;
} -
2015-10-17 17:01:35@
话说这题也爆0也太说不过去了吧
蒟蒻只能贴代码了,忘了怎么做了program p1398;
var
a,b,c,d,e:Array[1..10000]of longint;
i,j,n:longint;
procedure swap(var x,y:longint);
var t:longint;
begin
t:=x;x:=y;y:=t;
end;
procedure qsort(l,r:longint);
var
i,j,mid,t:longint;
begin
i:=l;j:=r;mid:=d[(l+r)shr 1];
repeat while d[i]<mid do inc(i);
while d[j]>mid do dec(j);
if i<=j then begin swap(a[i],a[j]);
swap(d[i],d[j]);swap(e[i],e[j]);inc(i);dec(j);end;
until i>j;
if i<r then qsort(i,r);
if l<j then qsort(l,j);
end;
begin
readln(n);
for i:=1 to n do begin read(a[i],b[i],c[i]);d[i]:=a[i]+b[i]+c[i];e[i]:=i;end;
qsort(1,n);
for i:=1 to n-1 do for j:=i+1 to n do
if d[i]=d[j] then if a[i]>a[j] then begin swap(a[i],a[j]);swap(e[i],e[j]);end
else if a[i]=a[j] then if e[i]<e[j] then swap(e[i],e[j]);
for i:=n downto n-4 do writeln(e[i],' ',d[i]);
end.
- 1