4 条题解
-
3莫言 (slz莫言) LV 10 @ 2024-11-29 18:11:03
#include <bits/stdc++.h> #define LL long long using namespace std; const int N = 1000 + 10; const int INF = 0x3f3f3f3f; int n , k; struct node { int id; int c; int m; int e; int sum; }; node a [N]; bool cmp (node a1 , node a2) { if (a1.sum == a2.sum) { return a1.id < a2.id; } return a1.sum > a2.sum; } int main() { cin >> n; for (int i = 1;i <= n; i++) { cin >> a [i].c >> a [i].m >> a [i].e; a [i].id = i; a [i].sum = a [i].c + a [i].m + a [i].e; } sort (a + 1 , a + n + 1 , cmp); for (int i = 1;i <= n; i++) { cout << a [i].c << " " << a [i].m << " " << a [i].e << " " << a [i].sum << "\n"; } return 0; }
-
32021-12-11 19:53:29@
#include <iostream> #include <stdio.h> #include <string.h> #include <queue> #include <math.h> #include <vector> #include <algorithm> #include <iomanip> #include <stack> using namespace std; #define LL long long const int N =1e5+10; const int INF =0x3f3f3f3f; struct node{ int name[100]; int c,m,e,s,id; }q[1000]; bool cmp(node a,node b){ if(a.s!=b.s) return a.s>b.s; return a.id<b.id; } int main(){ int n; cin>>n; for(int i=0;i<n;i++){ cin>>q[i].c>>q[i].m>>q[i].e; q[i].s=q[i].c+q[i].m+q[i].e; q[i].id=i; } sort(q,q+n,cmp); for(int i=0;i<n;i++){ cout<<q[i].c<<" "<<q[i].m<<" "<<q[i].e<<" "<<q[i].s<<endl; } return 0; }
-
22021-12-11 19:57:58@
#include <iostream> #include <stdio.h> #include <string.h> #include <queue> #include <math.h> #include <vector> #include <algorithm> #include <iomanip> #include <stack> using namespace std; #define LL long long const int N =1e5+10; const int INF =0x3f3f3f3f; struct node{ int name[100]; int c,m,e,s,id; }q[1000]; bool cmp(node a,node b){ if(a.s!=b.s) return a.s>b.s; return a.id<b.id; } int main(){ int n; cin>>n; for(int i=0;i<n;i++){ cin>>q[i].c>>q[i].m>>q[i].e; q[i].s=q[i].c+q[i].m+q[i].e; q[i].id=i; } sort(q,q+n,cmp); for(int i=0;i<n;i++){ cout<<q[i].c<<" "<<q[i].m<<" "<<q[i].e<<" "<<q[i].s<<endl; } return 0; }
-
02021-11-24 19:08:42@
C++ :
#include<iostream> #include<cstdio> using namespace std; int a[1001][5],n; void kp(int l,int r) { int t,x,i=l,j=r; x=a[(l+r)/2][3]; while(i<=j) { while(x>a[i][3])i++; while(x<a[j][3])j--; if(i<=j) { t=a[i][0];a[i][0]=a[j][0];a[j][0]=t; t=a[i][1];a[i][1]=a[j][1];a[j][1]=t; t=a[i][2];a[i][2]=a[j][2];a[j][2]=t; t=a[i][3];a[i][3]=a[j][3];a[j][3]=t; t=a[i][4];a[i][4]=a[j][4];a[j][4]=t; i++;j--; } } if(l<j)kp(l,j); if(i<r)kp(i,r); } int main() { scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d%d%d",&a[i][0],&a[i][1],&a[i][2]); a[i][3]=a[i][0]+a[i][1]+a[i][2];a[i][4]=i; } kp(1,n); int t; for(int i=1;i<=n;i++) { int k=i; while(a[i][3]==a[k][3])k++; k--; for(int j=k;j>=i;j--) for(int m=j;m<k;m++) if(a[m][4]<a[m+1][4]) { t=a[m][0];a[m][0]=a[m+1][0];a[m+1][0]=t; t=a[m][1];a[m][1]=a[m+1][1];a[m+1][1]=t; t=a[m][2];a[m][2]=a[m+1][2];a[m+1][2]=t; t=a[m][3];a[m][3]=a[m+1][3];a[m+1][3]=t; t=a[m][4];a[m][4]=a[m+1][4];a[m+1][4]=t; } } for(int i=n;i>=1;i--) printf("%d %d %d %d\n",a[i][0],a[i][1],a[i][2],a[i][3]); return 0; }
Pascal :
var a,b,c,d,e:array[1..1000] of longint; n,i:longint; procedure qsort(l,r:longint); var i,j,t,mid1,mid2:longint; begin i:=l; j:=r; mid1:=d[(i+j) div 2]; mid2:=e[(i+j) div 2]; repeat while (d[i]>mid1) or (d[i]=mid1) and (e[i]<mid2) do inc(i); while (d[j]<mid1) or (d[j]=mid1) and (e[j]>mid2) do dec(j); if i<=j then begin t:=a[i]; a[i]:=a[j]; a[j]:=t; t:=b[i]; b[i]:=b[j]; b[j]:=t; t:=c[i]; c[i]:=c[j]; c[j]:=t; t:=d[i]; d[i]:=d[j]; d[j]:=t; t:=e[i]; e[i]:=e[j]; e[j]:=t; inc(i); dec(j); end; until i>j; if l<j then qsort(l,j); if i<r then qsort(i,r); end; begin readln(n); for i:=1 to n do begin readln(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 do writeln(a[i],' ',b[i],' ',c[i],' ',d[i]); end.
- 1
信息
- ID
- 1489
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 6
- 标签
- 递交数
- 223
- 已通过
- 70
- 上传者