Module: コンパレータによるソート


Problem

3/11

最後の桁で並べ替える

Problem

一連の整数が与えられます。 数値の最後の桁の降順で配列を作成して並べ替えるプログラムを作成してください。

入力
最初に与えられた番号 N - 連続する要素の数 (1<= N <= 100)。次に、N 個の数字がスペースで区切られて書き込まれます。
 
出力
数字の下一桁で降順にソートした配列を出力する必要があります.
 
<頭> <本体>
# 入力 出力
1 5
5 100 23 777 34
777 5 34 23 100
Write the program below
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;


bool cmp(int first, int second) {
    
   
}

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(), cmp );
  
    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!