7dop
gorazd
c_cpp
a year ago
801 B
14
Indexable
2kolok_SP
#include <iostream>
#include <cctype>
#include <cstring>
using namespace std;
bool positive(int *arr, int len)
{
for (int i = 0; i < len; i++)
if (arr[i] < 0)
return false;
return true;
}
void premesti(int* arr, int len)
{
int end = len;
for (int i = 0; i < len; i++)
{
if (arr[i] < 0)
{
int tmp = arr[i];
for (int j = i; j < len; j++)
arr[j] = arr[j + 1];
arr[len - 1] = tmp;
end--;
i--;
}
if(positive(arr, end))
return;
}
}
int main() {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++)
{
cin >> arr[i];
}
premesti(arr, n);
for (int i = 0; i < n; i++)
{
cout << arr[i] << " ";
}
}
Editor is loading...
Leave a Comment