1 solutions
-
0
C++ :
#include<iostream> #include<algorithm> struct student { int id; int y; int s; int e; int tot; }; student a[301]; int n; using namespace std; void init(); void work(); bool comp(student a,student b) { if(a.tot==b.tot) { if(a.y==b.y) return a.id<b.id; return a.y>b.y; } return a.tot>b.tot; } int main() { init(); work(); return 0; } void init() { cin>>n; for(int i=0;i<n;++i) { cin>>a[i].y>>a[i].s>>a[i].e; a[i].id=i+1; a[i].tot=a[i].y+a[i].s+a[i].e; } } void work() { sort(a,a+n,comp); for(int i=0;i<4;++i) { cout<<a[i].id<<" "<<a[i].tot<<endl; } cout<<a[4].id<<" "<<a[4].tot; }Pascal :
var n,x,y,z,i,j:integer; a:array[1..300,1..3] of integer; procedure swap(var a,b:integer); {交换过程} var s:integer; begin s:=a; a:=b; b:=s; end; begin {assign(input,'scholar.in'); assign(output,'scholar.out'); reset(input); rewrite(output);} readln(n); for i:=1 to n do begin readln(x,y,z); a[i,1]:=i; a[i,2]:=x; a[i,3]:=x+y+z; end; for i:=1 to n-1 do {选择排序} for j:=i+1 to n do if (a[i,3]<a[j,3]) or ((a[i,3]=a[j,3]) and (a[i,2]<a[j,2])) or ((a[i,1]>a[j,1]) and (a[i,3]=a[j,3]) and (a[i,2]=a[j,2])) then begin swap(a[i,1],a[j,1]); swap(a[i,2],a[j,2]); swap(a[i,3],a[j,3]); end; for i:=1 to 5 do writeln(a[i,1],' ',a[i,3]); {close(input); {文件不要忘记关闭} close(output);} end.
- 1
Information
- ID
- 20057
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By