Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int s[1000], n, k, i, j, aux;
- cout << "n="; cin >> n;
- cout << "k="; cin >> k;
- for (i = 1; i <= n; i++)
- cin >> s[i];
- for (i = 1; i < k; i++) {
- for (j = i + 1; j <= k; j++) {
- if (s[i] > s[j]) {
- aux = s[i];
- s[i] = s[j];
- s[j] = aux;
- }
- }
- }
- for (i = k + 1; i < n; i++) {
- for (j = i + 1; j <= n; j++) {
- if (s[i] < s[j]) {
- aux = s[i];
- s[i] = s[j];
- s[j] = aux;
- }
- }
- }
- for (i = 1; i <= n; i++)
- cout <<s[i] << " ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement