Vector-Sort

  • + 0 comments

    I dont think my code (repeating for loop twice) looks beautiful, anyway it was very easy to "just solve" the problem.

    Wondering is there anything else i could learn from this problem.

    #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 */ 
        vector<int> v;
        int n, x;
        cin >> n;
        for(int i = 0; i < n; i++){
            cin >> x;
            v.push_back(x);
        }
        sort(v.begin(), v.end());
        for(int i = 0; i < n; i++){
            cout << v[i] << " ";
        }
        return 0;
    }