题解 | #寻找大富翁#
寻找大富翁
https://www.nowcoder.com/practice/38131e23663746a992581d45f16e7a86
#include <iostream> #include <algorithm> using namespace std; int wealth[100000 + 1]; bool cmp(int a, int b) { return a > b; } int main() { int n, m; while (cin >> n >> m) { if (n == 0) break; for (int i = 0; i < n; ++i) { cin >> wealth[i]; } sort(wealth, wealth + n, cmp); if (n < m) { for (int i = 0; i < n; ++i) { cout << wealth[i] << " "; } cout << endl; } else { for (int i = 0; i < m; ++i) { cout << wealth[i] << " "; } cout << endl; } } }