9 solutions

  • 1
    @ 2022-4-3 17:58:35

    这题,我觉得 放在这里 是想 让大家 手写 一下 一些 排序算法的。要不然 放在这里的 意义 真没多大。手写 排序 其实 真的 挺重要的,我听一个 大佬说过,有时候 要自己 写排序的。而且 排序的思想 很基础。

    #include <iostream>
    
    using namespace std;
    
    int arr1[500005];
    
    void quickSort(int l, int r) {
    	if (l >= r) {
    		return;
    	}
    	//int ic = arr1[r];
    	int midIndex = arr1[r];
    	int s = l;
    	int e = r - 1;
    	while (true) {
    		while (s < r && arr1[s] < midIndex) {
    			s++;
    		}
    		while (e >= l && arr1[e] > midIndex) {
    			e--;
    		}
    		if (s < e) {
    			int temp = arr1[s];
    			arr1[s] = arr1[e];
    			arr1[e] = temp;
    
    			// 继续 往下搜
    			s++;
    			e--;
    		}
    		else {
    			break;
    		}
    	}
    	int temp = arr1[s];
    	arr1[s] = arr1[r];
    	arr1[r] = temp;
    	quickSort(l,s -  1);
    	quickSort(s + 1, r);
    }
    
    
    
    int main(void) {
    	int n;
    	cin >> n;
    	for (int i = 0; i < n; ++i) {
    		cin >> arr1[i];
    	}
    
    	quickSort(0, n - 1);
    
    	for (int i = 0; i < n; ++i) {
    		cout << arr1[i] << " ";
    	}
    
    	return 0;
    }
    
    • 0
      @ 2022-2-12 17:05:26
      #define MaxSize 300001
      int hash[MaxSize];
      int main(){
      	int num;
      	int n;
      	scanf("%d",&num);
      	for(int i=0; i<num; i++){//整数的个数 
      		scanf("%d",&n);
      		hash[n]+=1;
      	}
      	for(int i=0; i<MaxSize; i++){
      		if(hash[i]>0){
      			for(int j=0; j<hash[i]; j++){
      				printf("%d ",i);
      			}
      		}
      	}
      	
      	
      }
      
      • @ 2022-2-12 17:05:48

        使用哈希数组,数组下标就是值

    • 0
      @ 2021-10-18 0:27:05

      看了题解才发现直接用sort就能过,我真是服了我自己了(用了快排)。。。。。

      • 0
        @ 2021-10-17 23:28:08

        sort解决问题

        • 0
          @ 2021-10-17 19:21:17

          sort排序大法好

          • 0
            @ 2021-10-17 16:28:48

            直接sort排序

            • 0
              @ 2021-10-17 13:28:39

              直接用sort就完事

              • 0
                @ 2021-10-16 19:23:44

                题目详解:

                使用sort函数进行排序即可,使用冒泡排序会有数据超时。

                • 0
                  @ 2021-10-14 20:41:19

                  简单的sort函数解决问题

                  • 1

                  Information

                  ID
                  109
                  Time
                  1000ms
                  Memory
                  256MiB
                  Difficulty
                  7
                  Tags
                  # Submissions
                  298
                  Accepted
                  78
                  Uploaded By