Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #include<ctime>
- #define zadanie 3
- int main()
- {
- srand(time(NULL));
- setlocale(LC_ALL, "RUS");
- #if zadanie == 1
- int M, N;
- cout << "Введите количество строк:";
- cin >> M;
- cout << "Введите количество столбцов:";
- cin >> N;
- char** ptr = new char* [M];
- for (int i = 0; i < M; i++) {
- ptr[i] = new char[N];
- for (int j = 0; j < N; j++) {
- ptr[i][j] = 48;
- cout << ptr[i][j] << " ";
- }
- cout << endl;
- }
- int x, y;
- char sym;
- cout << "Введите номер строки для разделяющего символа: ";
- cin >> x;
- cout << "Введите номер столбца для разделяющего символа: ";
- cin >> y;
- cout << "Введите разделяющий символ: ";
- cin >> sym;
- ptr[x][y] = sym;
- for (int i = 0; i < x; i++) {
- for (int j = 0; j < y; j++) {
- ptr[i][j] = 49;
- }
- }
- for (int i = 0; i < x; i++) {
- for (int j = y + 1; j < N; j++) {
- ptr[i][j] = 50;
- }
- }
- for (int i = x + 1; i < M; i++) {
- for (int j = 0; j < y; j++) {
- ptr[i][j] = 51;
- }
- }
- for (int i = x + 1; i < M; i++) {
- for (int j = y + 1; j < N; j++) {
- ptr[i][j] = 52;
- }
- }
- for (int i = 0; i < M; i++) {
- for (int j = 0; j < N; j++) {
- cout << ptr[i][j] << " ";
- }
- cout << endl;
- }
- #elif zadanie ==2
- int size, N, M, a, b, count;
- cout << "Введите размер массива: ";
- cin >> size;
- cout << "Введите диапазон возможных значений от и до: ";
- cin >> a >> b;
- int* arr = new int[size];
- for (int i = 0; i < size; i++) {
- arr[i] = a + rand() % (b - a + 1);
- cout << arr[i] << " ";
- }
- cout << endl;
- cout << "На какое количество массивов разбить: ";
- cin >> count;
- N = (ceil)((double)size / count);
- int** ptr = new int* [count];
- int ctr = 0;
- for (int i = 0; i < count - 1; i++) {
- ptr[i] = new int[N];
- for (int j = 0; j < N; j++) {
- ptr[i][j] = arr[ctr++];
- cout << ptr[i][j] << " ";
- }
- cout << endl;
- }
- for (int i = count - 1; i < count; i++) {
- ptr[i] = new int[size - ctr];
- if (ctr < size) {
- for (int j = 0; ctr < size; j++) {
- ptr[i][j] = arr[ctr++];
- cout << ptr[i][j] << " ";
- }
- }
- else {
- for (int j = 0; j<N; j++) {
- ptr[i][j] = 0;
- cout << ptr[i][j] << " ";
- }
- }
- cout << endl;
- }
- #elif zadanie == 3
- /*int* mass = new int[3 + rand() % 18];
- for (int i = 0; i < _msize(mass) / sizeof(int); i++) {
- mass[i] = rand() % 10;
- cout << mass[i] << " ";
- }
- cout << endl;*/
- int size;
- cout << "Введите размер массива: ";
- cin >> size;
- int* mass = new int[size];
- for (int i = 0; i < _msize(mass) / sizeof(int); i++) {
- cin >> mass[i];
- }
- cout << endl;
- int* ptr = mass;
- int sum = 0;
- while (ptr <= &mass[(_msize(mass) / sizeof(int)) - 1]) {
- cout << sum << endl;
- sum += *ptr;
- if (ptr == &mass[(_msize(mass) / sizeof(int)) - 1])break;
- if (ptr == &mass[(_msize(mass) / sizeof(int)) - 1] - 1)ptr = ptr + 1;
- else if (ptr == &mass[(_msize(mass) / sizeof(int)) - 1] - 2) { ((*(ptr + 1)) > (*(ptr + 2)) ? ptr += 1 : ptr += 2); }
- else if ((*(ptr + 1)) > (*(ptr + 2)) && (*(ptr + 1)) > 0)ptr += 1;
- else if ((*(ptr + 2)) > 0)ptr += 2;
- else if ((*(ptr + 1) + *(ptr + 3)) > (*(ptr + 2) + *(ptr + 4)))ptr += 1;
- else ptr += 2;
- }
- cout <<"Результат:"<< sum;
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement