메뉴 닫기

C++ vector for문 입력과 정렬

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
    vector<int> a;
    int n, x;
    cin >> n;

    for(int i=0; i<n; i++)  //입력 받고 push하기
    {
        cin >> x;
        a.push_back(x);
    }
    
    for(int i=0; i<n; i++)      //입력받은 순서로 출력
        cout << a[i] << " ";
    cout << endl ;

    sort(a.begin(), a.end());   //오름차순 정렬

    for(int i=0; i<n; i++)      //출력
        cout << a[i] << " ";
    cout << endl ;

    sort(a.begin(), a.end(), greater<int>());   //내림차순 정렬
    
    for(int i=0; i<n; i++)      //출력
        cout << a[i] << " ";
    cout << endl ;

    return 0;
}

2 Comments

  1. bedava bitcoin

    Thank you so much for giving everyone an extraordinarily breathtaking chance to check tips from here. It really is very kind and also stuffed with fun for me personally and my office peers to visit your web site not less than three times in a week to read through the fresh issues you will have. And definitely, I am also always fascinated with all the exceptional secrets you serve. Certain 1 areas on this page are rather the very best we have all had. Wally Coffman

  2. adult dating

    After all, we should remember compellingly reintermediate mission-critical potentialities whereas cross functional scenarios. Phosfluorescently re-engineer distributed processes without standardized supply chains. Quickly initiate efficient initiatives without wireless web services. Interactively underwhelm turnkey initiatives before high-payoff relationships. Holisticly restore superior interfaces before flexible technology. Sydney Hummell

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다