In this HackerRank Vector-Sort problem in c++, we have given N integers. Sort the N integers and print the sorted order.

HackerRank Vector-Sort in C++ problem solution

 

HackerRank Vector-Sort in C++ problem solution

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    int n;
    vector<int> v;
    scanf("%d", &n);
    int buf = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d", &buf);
        v.push_back(buf);
    }
    
    sort(v.begin(), v.end());
    
    for (int i = 0; i < v.size(); i++) {
        printf("%d ", v[i]);
    }
    
    return 0;
}