c2
This commit is contained in:
parent
0d75f30a49
commit
4744ebb565
69 changed files with 7 additions and 5 deletions
60
1sem/programming basics/09/100.cpp
Normal file
60
1sem/programming basics/09/100.cpp
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
// pb_9_100.cpp
|
||||
// Горбацевич Андрей
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int *read_array(int len)
|
||||
{
|
||||
int *out = new int[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
cout << "arr[" << i << "] >>>";
|
||||
cin >> *(out + i);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
void print_array(const int *arr, int len) {
|
||||
for (int i = 0; i < len; i++) {
|
||||
cout << *(arr + i) << " ";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
int my_task(const int *A, int lenA, int *B, int lenB) {
|
||||
int actbs = 0;
|
||||
int indx = -1;
|
||||
int *p = new int[lenB];
|
||||
for (int i = lenA; i >= 0;) {
|
||||
i -= 1;
|
||||
if (*(A + i) >= 0) {
|
||||
indx = i;
|
||||
break;
|
||||
}
|
||||
*(p + actbs++) = *(A + i);
|
||||
}
|
||||
delete[] B;
|
||||
B = new int[actbs];
|
||||
for (int i = 0; i < actbs; i++) {
|
||||
*(B + i) = *(p + (actbs-i-1));
|
||||
}
|
||||
return indx;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int len;
|
||||
cout << "len >>>";
|
||||
cin >> len;
|
||||
int *a1 = read_array(len);
|
||||
int *b = new int[len];
|
||||
int indx = my_task(a1, len, b, len);
|
||||
if (indx > -1) {
|
||||
cout << "Last positive: " << indx;
|
||||
}
|
||||
else {
|
||||
cout << "No positive elements";
|
||||
}
|
||||
cout << endl << "B = ";
|
||||
print_array(b, len-1-indx);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue