Problem

7/11

通过 lambda 函数对向量进行排序

Problem

给你一个整数序列。编写一个程序,按降序创建数组并对其进行排序。
 
输入
第一个给定的数字N —数组中元素的数量 (1<=N<=100)。进一步,通过空格,写下N个数字——数组元素。该数组由整数组成。
 
输出
需要输出一个降序排列的数组。
  <正文>
输入 输出
5
4 56 23 67 100
100 67 56 23 4
Write the program below
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {

int N;

cin >> N;
vector<int> A (N);


    for(int i = 0; i < N; i++)
        cin>>A[i];
    sort(A.begin(), A.end(), 
   
 
    for(int i = 0;i< N; i ++)
      cout<<A[i]<<" ";
}    

     

Program check result

To check the solution of the problem, you need to register or log in!