1 solutions

  • 0
    @ 2023-10-30 19:19:10

    这道题是个简单思维题(难度被砍了90%),考察的就是你有没有想到排序,由于题目告诉了我们一定有对应的答案,那么排序的话必定可以直接做出来。m其实都可以不用管。甚至这题数据被砍得连冒泡排序都能过。

    直接上代码。

    #include <stdio.h>
    void mao(int a[],int n)
    {
    	for(int i = 0; i < n - 1; i++){
        	for(int j = 0; j < n - 1 - i; j++){
        		if(a[j] > a[j + 1]){
        			int x = a[j];
        			a[j] = a[j + 1];
        			a[j + 1] = x;
    			}
    		}
    	}
    }
    int main()
    {
        int n,k;
        scanf("%d%d",&n,&k);
        int c[n],b[n];
        for(int i = 0; i < n; i++)scanf("%d",&c[i]);
        for(int i = 0; i < n; i++)scanf("%d",&b[i]);
        mao(c, n);
        mao(b, n);
        for(int i = 0; i < n; i++)printf("%d ",c[i]);
        printf("\n");
        for(int i = 0; i < n; i++)printf("%d ",b[i]);
        return 0; 
    }
    

    c++甚至直接sort秒了。

    #include<iostream>
    #include<algorithm>
    #include<cstring>
    #include<vector>
    #include<cmath>
    using namespace std;
    #define ll long long
    ll n,a,b,T,k,m;
    const int N = 1e5 + 10;
    
    
    int main()
    {
    	int a[N];
    	int b[N];
    	cin >> n >> m;
    	for(int i = 0; i < n; i++){
    		scanf("%d",&a[i]);
    	}
    	for(int i = 0; i < n; i++){
    		scanf("%d",&b[i]);
    	}
    	sort(a, a + n);
    	sort(b, b + n);
    	for(int i = 0; i < n; i++){
    		cout << a[i] << ' ';
    	}
    	cout<<"\n";
    	for(int i = 0; i < n; i++){
    		cout << b[i] << ' ';
    	}
    	return 0;
    }
    

    Information

    ID
    6942
    Time
    100ms
    Memory
    64MiB
    Difficulty
    1
    Tags
    (None)
    # Submissions
    188
    Accepted
    23
    Uploaded By