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