initial
This commit is contained in:
commit
2802401eee
79 changed files with 2650 additions and 0 deletions
60
1sem/programming basics/8/2_100.cpp
Normal file
60
1sem/programming basics/8/2_100.cpp
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
// pb_8_2_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(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