2 solutions
-
0
#include <stdio.h> int main() { struct student { int num; float a; float b; }; int n; scanf("%d", &n); struct student stu[10000]; struct student* p; p = &stu; struct student k; int i, j; for (i = 0; i < n; i++) { stu[i].num = i + 1; } for (i = 0; i < n; i++) { scanf("%f%f", &(*p).a, &(*p).b); p++; } for (i = 0; i < n - 1; i++) { for (j = i + 1; j < n; j++) { if (stu[i].a > stu[j].a) { k = stu[i]; stu[i] = stu[j]; stu[j] = k; } if (stu[i].a == stu[j].a) { if (stu[i].b > stu[j].b) { k = stu[i]; stu[i] = stu[j]; stu[j] = k; } else if (stu[i].b == stu[j].b) { if (stu[i].num > stu[j].num) { k = stu[i]; stu[i] = stu[j]; stu[j] = k; } } } } } for (i = 0; i < n; i++) printf("%d ", stu[i].num); return 0; }
-
0
#include<bits/stdc++.h> #define ll long long using namespace std; template<typename T> inline void in (T &x) {char c;int f=1;do {c=getchar ();if (c=='-') f=-1;} while (c>'9' || c<'0');for (x=0;c>='0' && c<='9';c=getchar ()) x=(x<<1)+(x<<3)+(c^48);x*=f;} template<typename T> inline void out (T x,char c) {if (x==0) {putchar ('0'),putchar (c); return ;}if (x<0)putchar ('-'),x=-x;int sta[20],k=0;while (x) sta[++k]=x%10,x/=10;while (k) putchar (sta[k--]+'0');putchar (c);} const int N=1e3+5; struct node{ int chi,mat,id; }a[N]; int n; bool cmp(node x,node y){ if(x.chi==y.chi){ if(x.mat==y.mat){ return x.id<y.id; } return x.mat<y.mat; } return x.chi<y.chi; } int main(){ // freopen ("std.in","r",stdin); // freopen (".out","w",stdout); ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); in(n); for(int i=1;i<=n;++i){ in(a[i].chi),in(a[i].mat); a[i].id=i; } sort(a+1,a+n+1,cmp); for(int i=1;i<=n;++i){ out(a[i].id,' '); } return 0; }
- 1
Information
- ID
- 6828
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 7
- Tags
- # Submissions
- 98
- Accepted
- 20
- Uploaded By