Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <random>
- #include <cmath>
- #include <time.h>
- using namespace std;
- void print(int(&a)[1000], int n) {
- for (int i = 0; i < n; ++i)
- cout << a[i] << " ";
- cout << '\n';
- }
- bool keyb_fill(int (&a)[1000], int & n) {
- cout << "Enter amout of elements\n";
- cin >> n;
- if (n > 1000) {
- cout << "Incorrect amout of elements\n";
- return false;
- }
- cout << "Enter elements\n";
- for (int i = 0; i < n; ++i)
- cin >> a[i];
- return true;
- }
- bool rand_fill(int(&a)[1000], int& n) {
- cout << "Enter amout of elements\n";
- cin >> n;
- if (n > 1000) {
- cout << "Incorrect amout of elements\n";
- return false;
- }
- for (int i = 0; i < n; ++i)
- a[i] = (int)pow(-1, rand() % 2) * rand() % 1000;
- print(a, n);
- return true;
- }
- bool fill(int(&a)[1000], int & n) {
- int x = 0;
- cout << "Manual fill? (yes - 1, no - 0)\n";
- cin >> x;
- if (x == 1) return keyb_fill(a, n);
- else return rand_fill(a, n);
- }
- int first_enter(int(&a)[1000], int n, int x) {
- for (int i = 0; i < n; ++i)
- if (a[i] == x)
- return i;
- return -1;
- }
- int first_negative(int(&a)[1000], int n, int x) {
- for (int i = 0; i < n; ++i)
- if (a[i] < x)
- return i;
- return -1;
- }
- void enters(int(&a)[1000], int n, int x, int(&b)[1000], int& cnt) {
- cnt = 0;
- for (int i = 0; i < n; ++i)
- if (a[i] == x) {
- b[cnt] = i;
- cnt++;
- }
- }
- void put(int(&a)[1000], int & n, int x, int ptr) {
- for (int i = n - 1; i >= ptr; i--) {
- a[i + 1] = a[i];
- }
- a[ptr] = x;
- n++;
- }
- void del_ptr (int(&a)[1000], int& n, int ptr) {
- for (int i = ptr; i < n - 1; ++i)
- a[i] = a[i + 1];
- n--;
- }
- void del_n2(int(&a)[1000], int& n, int x) {
- for (int i = 0; i < n; ++i) {
- if (a[i] == x) {
- for (int j = i; j < n - 1; ++j)
- a[j] = a[j + 1];
- n--;
- }
- }
- }
- void del_n(int(&a)[1000], int& n, int x) {
- int b[1000];
- int cnt = 0;
- for (int i = 0; i < n; ++i)
- if (a[i] != x) {
- b[cnt] = a[i];
- cnt++;
- }
- n = cnt;
- memcpy(a, b, cnt);
- }
- int main() {
- srand(time(NULL));
- int n = 0;
- int a[1000];
- for (int i = 0; i < 1000; ++i)
- a[i] = 0;
- fill(a, n);
- cout << "Array:\n";
- print(a, n);
- n = 0;
- for (int i = 0; i < 1000; ++i)
- a[i] = 0;
- fill(a, n);
- cout << "Array:\n";
- print(a, n);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement