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 }
原文地址:https://www.cnblogs.com/Artimis-fightting/p/10983012.html
时间: 2024-10-30 22:57:31