4 solutions

  • 0
    @ 2025-3-5 19:55:52

    import java.util.Arrays; import java.util.Comparator; import java.util.Scanner;

    public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int[][] Score = new int[n][3]; for(int i = 1; i <= n; i++){ Score[i-1][0] = i; Score[i-1][1] = scan.nextInt(); Score[i-1][2] = scan.nextInt(); } Arrays.sort(Score, new Comparator<int[]>() { @Override public int compare(int[] o1, int[] o2) { if(o1[1]!=o2[1]){ return o1[1] - o2[1]; }else { if(o1[2]!=o2[2]){ return o1[2] - o2[2]; }else { return o1[0] - o2[0]; } } } }); for(int[] arr : Score){ System.out.print(arr[0] + " "); } } }

    • 0
      @ 2024-12-4 23:11:24

      #include<bits/stdc++.h> using namespace std; const int N=1e4; struct student{ int yu; int shu; int xh; }; int main() { int n,i,m; cin>>n; struct student s[N],temp; for(i=1;i<=n;i++){ cin>>s[i].yu>>s[i].shu; s[i].xh=i; } for(i=1;i<n;i++){ for(m=1;m<=n-i;m++){ if(s[m].yu>s[m+1].yu){ temp=s[m]; s[m]=s[m+1]; s[m+1]=temp; } else if(s[m].yus[m+1].yu&&s[m].shu>s[m+1].shu){ temp=s[m]; s[m]=s[m+1]; s[m+1]=temp; } else if(s[m].yus[m+1].yu&&s[m].shu==s[m+1].shu){ if(s[m].xh>s[m+1].xh){ temp=s[m]; s[m]=s[m+1]; s[m+1]=temp; } } } } for(i=1;i<=n;i++){ cout<<s[i].xh<<" "; } return 0; }

      • 0
        @ 2023-10-18 12:49:24
        #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
          @ 2023-9-2 21:41:55
          #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
          108
          Accepted
          25
          Uploaded By