HDU 3785 找寻大富翁
2019-06-06
08:30:03
坚持!!!
做这些水题,都觉得心累,特别是HDU的题,我PE了3发😭
输出每行末尾没有空格,诶……
1 #include <bits/stdc++.h> 2 using namespace std; 3 int a[100005]; 4 int main() 5 { 6 int n, m; 7 while(~scanf("%d %d", &n, &m)) 8 { 9 if(n == 0 && m == 0) 10 { 11 break; 12 } 13 for (int i = 0; i < n; i++) 14 { 15 scanf("%d", &a[i]); 16 } 17 sort(a, a + n); 18 for (int i = n - 1,j =0 ; i >= 0 && j < m ; i--, j++) 19 { 20 if(j == m - 1) 21 cout << a[i] ; 22 else 23 cout << a[i] << " "; 24 } 25 cout << endl; 26 } 27 return 0; 28 }