Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

222-9+11+12:2*14+14 = ? ( )

Toán Lớp 8: Sắp xếp không giảm c++ Cho một dãy gồm n số nguyên dương A1,A2,…,An. (N≤104,Ai≤109). Hãy in ra dãy số sau khi sắp xếp dãy số tăng dần (

Toán Lớp 8: Sắp xếp không giảm c++
Cho một dãy gồm n số nguyên dương A1,A2,…,An. (N≤104,Ai≤109). Hãy in ra dãy số sau khi sắp xếp dãy số tăng dần (Ai≤Ai+1).
Input
Dòng đầu chứa số n,
Dòng thứ hai chứa n số nguyên dương A1,A2,…,An.
Output
Một dòng chứa dãy số đã sắp xếp tăng dần.
Sample Input
6
91 451 43 3 451 54
Sample Output
3 43 54 91 451 451

Comments ( 2 )

  1. #include <vector>
    #include <iostream>
    #include <algorithm>
    #define a(x) (x).begin(), (x).end()
    using namespace std;

    vector<int>a;int n;inline int readInt() {char c;while(c=getchar(),c!=’-‘&&(c<‘0’||c>’9′));bool sign=(c==’-‘);if(sign)c=getchar();int n=c-‘0′;while(c=getchar(),c>=’0’&&c<=’9’)n=10*n+c-‘0’;return(!sign)?n:-n;}

    int main() {
        ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
        n=readInt(); for (int i=0;i<n;++i) a.push_back(readInt());
        sort(a(a)); for (auto x:a)cout<<x<<‘ ‘;
    }

  2. Giải đáp:
    ↓↓
    Lời giải và giải thích chi tiết:
    #include <bits/stdc++.h>
    #define ll long long
    #define ull unsigned long long
    using namespace std;

    int main() {
        ios::sync_with_stdio(0);
        cin.tie(0);cout.tie(0);
        ll n;
        cin >> n;
        ll a[n];
        for(int i = 0; i < n; i++) {
            cin >> a[i];
        }
        sort(a,a + n,greater<int>());
        for(int i = 0; i < n; i++) {
            cout << a[i] << ” “;
        }
    }

Leave a reply

222-9+11+12:2*14+14 = ? ( )