1 solutions

  • 0
    @ 2024-12-10 23:39:22

    C :

    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    int s[100005],n,i;
    int cmp(const void *a,const void *b)
    {
         return(*(int *)a-*(int *)b);//ÉýÐò£»b-a½µÐò
    }
    int main()
    {
        scanf("%d",&n);
        for(i=0;i<n;i++)
    	    scanf("%d",&s[i]);
        qsort(s,n,sizeof(s[0]),cmp);
        for(i=0;i<n;i++)
    	    printf("%d ",s[i]);
      printf("\n");
        return 0;
    }
    
    

    C++ :

    #include <cstdio>
    #include <cstdlib>
    #include <stack>
    #include <algorithm>
    using namespace std;
    const int MAXN = 100000;
    int val[MAXN];
    int n;
    void QSort(int l, int r) {
    	if (l <= r) {
    		int pivot = val[l + rand() % (r - l + 1)];
    		int low = l, high = r;
    		while (low <= high) {
    			while (val[low] < pivot)
    				low++;
    			while (val[high] > pivot)
    				high--;
    			if (low <= high) {
    				swap(val[low], val[high]);
    				low++;
    				high--;
    			}
    		}
    		QSort(l, high);
    		QSort(low, r);
    	}
    }
    void QuickSort() {
    	QSort(0, n - 1);
    }
    int main() {
    	scanf("%d", &n);
    	for (int i = 0;i < n;i++) {
    		scanf("%d", &val[i]);
    	}
    	QuickSort();
    	for (int i = 0;i < n;i++) {
    		printf("%d ", val[i]);
    	}
    	puts("");
    	return 0;
    }
    

    Pascal :

    var a:array[1..100000] of longint;
        i,n:longint;
    procedure qsort(l,r:longint);
    var i,j,mid,p:longint;
    begin
      i:=l; j:=r;
      mid:=a[(l+r) div 2];
      while i<=j do
      begin
        while a[i]<mid do inc(i);
        while a[j]>mid do dec(j);
        if i<=j then
        begin
          p:=a[i];
          a[i]:=a[j];
          a[j]:=p;
          inc(i);
          dec(j);
        end;
      end;
      if l<j then qsort(l,j);
      if i<r then qsort(i,r);
    end;
    
    begin
      read(n);
      for i:=1 to n do
        read(a[i]);
      qsort(1,n);
      for i:=1 to n do
        write(a[i],' ');
    end.
    

    Java :

    
    
    import java.util.Arrays;
    import java.util.Scanner;
    
    public class Main{
      private static Scanner s = new Scanner(System.in) ;
      
      public static void main(String[] args) {
    	 int num = s.nextInt() ;
    	 if(num<=100000){
    	 int a[] = new int[num] ;
    	 for (int i = 0; i < num; i++) {
    		a[i] = s.nextInt() ;
    	 }
    	 
    	 Arrays.sort(a);
    	 
    	 for (int i = 0; i < a.length; i++) {
    		System.out.print(a[i]+" "); 
    	  }
    	 System.out.println();
    	 }
      }
    }
    
    
    • 1

    Information

    ID
    612
    Time
    1000ms
    Memory
    32MiB
    Difficulty
    10
    Tags
    # Submissions
    2
    Accepted
    2
    Uploaded By