題解 | STL
輸入整型數(shù)組和排序標(biāo)識(shí),對(duì)其元素按照升序或降序進(jìn)行排序
http://fangfengwang8.cn/practice/dd0c6b26c9e541f5b935047ff4156309
#include <algorithm> #include <iostream> #include <bits/stdc++.h> #include <vector> using namespace std; int main() { int n; cin >> n; vector<int> data(n); for(int i = 0; i < n; ++i) { cin >> data[i]; } int flag; cin >> flag; sort(begin(data), end(data)); if (flag == 0) { for (int i = 0; i < n; ++i) { cout << data[i]; if (i < n - 1) { cout << " "; } else { cout << endl; } } } else { for (int i = n - 1; i >= 0; --i) { cout << data[i]; if (i > 0) { cout << " "; } else { cout << endl; } } } } // 64 位輸出請(qǐng)用 printf("%lld")