Fixed up to 6 (including)

This commit is contained in:
2024-12-14 13:35:13 +03:00
parent 42cb45db32
commit d07a6428a5
10 changed files with 94 additions and 168 deletions

View File

@@ -1,4 +1,4 @@
#include <iostream>
#include <iostream>
#include "task1.h"
#include "task2.h"
#include "task3.h"
@@ -8,11 +8,11 @@
#include "task7.h"
#include "task8.h"
#include "task9.h"
#include "task10.h"
using namespace std;
int main()
{
setlocale(LC_ALL, "Russian");
int id;
bgn:
cout << "Task id : "; cin >> id;
@@ -46,11 +46,8 @@ int main()
case 9:
task9::init();
break;
case 10:
task10::init();
break;
}
cout << endl;
goto bgn;
}
}

20
task1.h
View File

@@ -5,7 +5,7 @@ using namespace std;
namespace task1 {
int F(int num); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
int F(int num); // num table
int a(int* m, int size);
int b(int* m, int size);
int v(int* m, int size);
@@ -18,18 +18,18 @@ namespace task1 {
cout << "TASK #1" << endl;
setlocale(LC_ALL, "Russian");
int n;
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: "; cin >> n;
cout << "Введите длину: "; cin >> n;
int* m = new int[n];
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>: " << endl;
cout << "Введите элементы: " << endl;
for (int i = 0; i < n; i++) { cin >> m[i]; }
cout << "<EFBFBD>) " << a(m, n) << endl;
cout << "<EFBFBD>) " << b(m, n) << endl;
cout << "<EFBFBD>) " << v(m, n) << endl;
cout << "<EFBFBD>) " << g(m, n) << endl;
cout << "<EFBFBD>) " << d(m, n) << endl;
cout << "<EFBFBD>) " << e(m, n) << endl;
cout << "а) " << a(m, n) << endl;
cout << "б) " << b(m, n) << endl;
cout << "в) " << v(m, n) << endl;
cout << "г) " << g(m, n) << endl;
cout << "д) " << d(m, n) << endl;
cout << "е) " << e(m, n) << endl;
delete[] m;
return 0;
@@ -132,4 +132,4 @@ namespace task1 {
}
return n;
}
}
}

View File

@@ -1,45 +0,0 @@
#include <iostream>
#include <queue>
#include <fstream>
#include <string>
using namespace std;
#pragma once
namespace task10 {
int init()
{
cout << "TASK #9" << endl;
setlocale(LC_ALL, "Russian");
queue<int> dig1;
ifstream input("C:\\input2.txt");
string data;
while (getline(input, data))
{
if (data.size() == 2)
{
dig2.push(n);
}
}
while (!dig1.empty())
{
cout << dig1.front() << endl;
dig1.pop();
}
while (!dig2.empty())
{
cout << dig2.front() << endl;
dig2.pop();
}
cout << "<EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>))" << endl;
return 0;
}
}

View File

@@ -9,16 +9,16 @@ namespace task2 {
cout << "TASK #2" << endl;
setlocale(LC_ALL, "Russian");
int n; cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: "; cin >> n;
int n; cout << "Введите размер: "; cin >> n;
int amt = 0, sum = 0;
int* m = new int[n];
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>:" << endl;
cout << "Введите числа:" << endl;
for (int i = 0; i < n; i++) {
int num; cin >> num;
m[i] = num; //<2F><> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>
m[i] = num;
if (num % 5 == 0 && num % 7 != 0)
{
amt++;
@@ -26,7 +26,7 @@ namespace task2 {
}
}
cout << "<EFBFBD><EFBFBD><EFBFBD>-<2D><>: " << amt << endl << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: " << sum;
cout << "Кол-во: " << amt << endl << "Сумма: " << sum;
delete[] m;
return 0;

12
task3.h
View File

@@ -11,10 +11,10 @@ namespace task3 {
cout << "TASK #3" << endl;
setlocale(LC_ALL, "Russian");
int n; cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: "; cin >> n;
int n; cout << "Введите длину: "; cin >> n;
int amt = 0;
int* m = new int[n];
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>: " << endl;
cout << "Введите числа: " << endl;
for (int i = 0; i < n; i++)
{
cin>>m[i];
@@ -27,12 +27,10 @@ namespace task3 {
max = cur > max ? cur : max;
}
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> " << max * (max!=1) << " <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>\n";
cout << "<EFBFBD>) " << (max >= 2) << endl;
cout << "<EFBFBD>) " << (max >= 3) << endl;
cout << "а) " << (max >= 2) << endl;
cout << "б) " << (max >= 3) << endl;
delete[] m;
return 0;
}
}
}

14
task4.h
View File

@@ -1,6 +1,8 @@
#include <iostream>
#pragma once
using namespace std;
namespace task4 {
struct Node
@@ -10,17 +12,17 @@ namespace task4 {
Node* next;
};
Node* newNode(int key); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
Node* list(int size, bool print); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int sum(Node* head); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
Node* newNode(int key);
Node* list(int size, bool print);
int sum(Node* head);
int init()
{
setlocale(LC_ALL, "Russian");
int n; cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: "; cin >> n;
int n; cout << "Введите длину: "; cin >> n;
Node* array = list(n, true);
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: " << sum(array);
cout << "Сумма: " << sum(array);
return 0;
}
@@ -66,4 +68,4 @@ namespace task4 {
return sum;
}
}
}

View File

@@ -9,9 +9,9 @@ namespace task5 {
cout << "TASK #5" << endl;
setlocale(LC_ALL, "Russian");
int n; cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: "; cin >> n;
int n; cout << "Ввелите длину: "; cin >> n;
double* m = new double[n];
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>:" << endl;
cout << "Введите элементы:" << endl;
for (int i = 0; i < n; i++)
{
cin >> m[i];
@@ -23,14 +23,14 @@ namespace task5 {
double num = m[i];
if (num > min)
{
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. " << endl;
cout << "Массив не упорядочен по убыванию. " << endl;
delete[] m;
return 0;
}
min = num;
}
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. " << endl;
cout << "Массив упорядочен по убыванию. " << endl;
delete[] m;
return 0;
}

52
task6.h
View File

@@ -1,4 +1,4 @@
#include <iostream>
#include <iostream>
using namespace std;
#pragma once
@@ -11,52 +11,50 @@ namespace task6 {
Node* next;
};
Node* newNode(int key); //создает узел
Node* rand_list(int size); //создает список
void print_list(Node* head); //пишет элементы списка
Node* newNode(int key);
Node* rand_list(int size);
void print_list(Node* head);
bool is_list_empty(Node* head); //пишет, что список пуст, если подкинуть nullptr
void push_back(Node* head, int key); //поместить в конец
void push_forward(Node*& head, int key); //поместить в начало
void squeeze_in(Node* head, int pos, int key); //"всунуть" после элемента
bool is_list_empty(Node* head);
void push_back(Node* head, int key);
void push_forward(Node*& head, int key);
void squeeze_in(Node* head, int pos, int key);
int list_size(Node* head); //узнать размер списка
void behead(Node*& head); //получить список без первого элемента
int list_size(Node* head);
void behead(Node*& head);
int init()
{
setlocale(LC_ALL, "Russian");
int n; cout << "Введите размер: "; cin >> n;
int n; cout << "Введите длину: "; cin >> n;
Node* lst = rand_list(n);
if (is_list_empty(lst))
{
cout << "Список является пустым." << endl;
cout << "Список пуст." << endl;
return 0;
}
cout << "Список содержит элементы: " << endl;
cout << "Список: " << endl;
print_list(lst);
cout << "\n\nДобавим элемент 11111 в начало:" << endl;
cout << "Добавим в начало 11111:" << endl;
push_forward(lst, 11111);
print_list(lst);
cout << "\n\nДобавим элемент 22222 в конец:" << endl;
cout << "Добавим в конец 22222:" << endl;
push_back(lst, 22222);
print_list(lst);
cout << "\n\nДобавим элемент 33333 где-то в середине:" << endl;
cout << "Добавим в середину 33333:" << endl;
squeeze_in(lst, n/2+1, 33333);
print_list(lst);
cout << "\n\nВсего элементов сейчас: " << list_size(lst) << endl;
cout << "Длина списка: " << list_size(lst) << endl;
cout << "\n\nПолучим список без первого элемента с помощью функции обезглавливания:" << endl;
cout << "Список без первого элемента:" << endl;
behead(lst);
print_list(lst);
cout << "\n\nДа это жоско";
return 0;
}
@@ -158,18 +156,6 @@ namespace task6 {
void behead(Node*& head)
{
/*
⢿⣿⣿⣿⣭⠹⠛⠛⠛⢿⣿⣿⣿⣿⡿⣿⠷⠶⠿⢻⣿⣛⣦⣙⠻⣿
⣿⣿⢿⣿⠏⠀⠀⡀⠀⠈⣿⢛⣽⣜⠯⣽⠀⠀⠀⠀⠙⢿⣷⣻⡀⢿
⠐⠛⢿⣾⣖⣤⡀⠀⢀⡰⠿⢷⣶⣿⡇⠻⣖⣒⣒⣶⣿⣿⡟⢙⣶⣮
⣤⠀⠀⠛⠻⠗⠿⠿⣯⡆⣿⣛⣿⡿⠿⠮⡶⠼⠟⠙⠊⠁⠀⠸⢣⣿
⣿⣷⡀⠀⠀⠀⠀⠠⠭⣍⡉⢩⣥⡤⠥⣤⡶⣒⠀⠀⠀⠀⠀⢰⣿⣿
⣿⣿⡽⡄⠀⠀⠀⢿⣿⣆⣿⣧⢡⣾⣿⡇⣾⣿⡇⠀⠀⠀⠀⣿⡇⠃
⣿⣿⣷⣻⣆⢄⠀⠈⠉⠉⠛⠛⠘⠛⠛⠛⠙⠛⠁⠀⠀⠀⠀⣿⡇⢸
⢞⣿⣿⣷⣝⣷⣝⠦⡀⠀⠀⠀⠀⠀⠀⠀⡀⢀⠀⠀⠀⠀⠀⠛⣿⠈
⣦⡑⠛⣟⢿⡿⣿⣷⣝⢧⡀⠀⠀⣶⣸⡇⣿⢸⣧⠀⠀⠀⠀⢸⡿⡆
⣿⣿⣷⣮⣭⣍⡛⠻⢿⣷⠿⣶⣶⣬⣬⣁⣉⣀⣀⣁⡤⢴⣺⣾⣽⡇
*/
head = head->next;
}
}
}

84
task7.h
View File

@@ -1,4 +1,4 @@
#include <iostream>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
@@ -13,46 +13,46 @@ namespace task7 {
Node* next;
};
Node* newNode(int key); //создает узел
Node* rand_list(int size); //создает список
void print_list(Node* head); //пишет элементы списка
Node* newNode(int key);
Node* rand_list(int size);
void print_list(Node* head);
bool is_list_empty(Node* head); //пишет, что список пуст, если подкинуть nullptr
void push_back(Node* head, int key); //поместить в конец
void push_forward(Node*& head, int key); //поместить в начало
void squeeze_in(Node* head, int pos, int key); //"всунуть" после элемента
bool is_list_empty(Node* head);
void push_back(Node* head, int key);
void push_forward(Node*& head, int key);
void squeeze_in(Node* head, int pos, int key);
void behead(Node*& head);
int list_size(Node* head); //узнать размер списка
int list_size(Node* head);
bool equal(Node* head1, Node* head2); //сравнивает списки
bool all_in(Node* head1, Node* head2); //проверяет, есть ли все элементы первого списка в другом
bool dupes_present(Node* head); //проверка на дубликаты
void head_to_end(Node*& head); //перемещает первый элемент в конец
void end_to_head(Node*& head); //перемещает последний элемент в начало
void merge(Node* head1, Node* head2); //переносит элементы списка 2 в конец списка 1
void reversed(Node*& head); //возвращает элементы массива в обрат. порядке
bool in_list(Node* head, int key); //ДЛЯ ЗАДАНИЯ ПОД БУКВОЙ З). Определяет, есть ли элемент в списке
void remove_dupes(Node*& head); //not implemented
bool equal(Node* head1, Node* head2);
bool all_in(Node* head1, Node* head2);
bool dupes_present(Node* head);
void head_to_end(Node*& head);
void end_to_head(Node*& head);
void merge(Node* head1, Node* head2);
void reversed(Node*& head);
bool in_list(Node* head, int key);
void remove_dupes(Node*& head); // not implemented
int init()
{
cout << "TASK #7" << endl;
setlocale(LC_ALL, "Russian");
cout << "В конце задания 6 ничего не предвещало беды\n";
cout << "В конце задания 6 ничего не предвещало беды\n";
int n1; cout << "Введите размер списка 1: "; cin >> n1;
int n1; cout << "Введите размер списка 1: "; cin >> n1;
Node* lst1 = newNode(0);
cout << "Введите числа:" << endl;
cout << "Введите числа:" << endl;
for (int i = 0; i < n1; i++)
{
int num; cin >> num;
push_back(lst1, num);
}
int n2; cout << "Введите размер списка 2: "; cin >> n2;
int n2; cout << "Введите размер списка 2: "; cin >> n2;
Node* lst2 = newNode(0);
cout << "Введите числа:" << endl;
cout << "Введите числа:" << endl;
for (int i = 0; i < n2; i++)
{
int num; cin >> num;
@@ -60,61 +60,61 @@ namespace task7 {
}
behead(lst1);
behead(lst2);
cout << "\n\nИмеем два списка: \n";
cout << "\n\nИмеем два списка: \n";
print_list(lst1);
print_list(lst2);
cout << "\n\n";
if (equal(lst1, lst2))
{
cout << "Списки совпадают";
cout << "Списки совпадают";
}
else
{
cout << "Списки не равны";
cout << "Списки не равны";
}
cout << "\n\n";
if (all_in(lst1, lst2))
{
cout << "Все элементы первого списка есть во втором";
cout << "Все элементы первого списка есть во втором";
}
else
{
cout << "Первый список имеет элементы, которых нет во втором";
cout << "Первый список имеет элементы, которых нет во втором";
}
cout << "\n\n";
if (dupes_present(lst1))
{
cout << "В списке есть дубликаты";
cout << "В списке есть дубликаты";
}
else
{
cout << "В списке нет дубликатов";
cout << "В списке нет дубликатов";
}
cout << "\n\n";
print_list(lst1);
cout << "Перенесем первый элемент списка 1 в конец : \n";
cout << "Перенесем первый элемент списка 1 в конец : \n";
head_to_end(lst1);
print_list(lst1);
cout << "\n\n";
print_list(lst2);
cout << "Перенесем последний элемент списка 2 в начало : \n";
cout << "Перенесем последний элемент списка 2 в начало : \n";
end_to_head(lst2);
print_list(lst2);
cout << "\n\n";
print_list(lst1);
print_list(lst2);
cout << "Соединим два списка: \n";
cout << "Соединим два списка: \n";
merge(lst1, lst2);
print_list(lst1);
cout << "Развернем список: \n";
cout << "Развернем список: \n";
reversed(lst1);
print_list(lst1);
cout << "Удалим дубликаты из списка: \n";
cout << "Удалим дубликаты из списка: \n";
remove_dupes(lst1);
print_list(lst1);
@@ -204,18 +204,6 @@ namespace task7 {
void behead(Node*& head)
{
/*
⢿⣿⣿⣿⣭⠹⠛⠛⠛⢿⣿⣿⣿⣿⡿⣿⠷⠶⠿⢻⣿⣛⣦⣙⠻⣿
⣿⣿⢿⣿⠏⠀⠀⡀⠀⠈⣿⢛⣽⣜⠯⣽⠀⠀⠀⠀⠙⢿⣷⣻⡀⢿
⠐⠛⢿⣾⣖⣤⡀⠀⢀⡰⠿⢷⣶⣿⡇⠻⣖⣒⣒⣶⣿⣿⡟⢙⣶⣮
⣤⠀⠀⠛⠻⠗⠿⠿⣯⡆⣿⣛⣿⡿⠿⠮⡶⠼⠟⠙⠊⠁⠀⠸⢣⣿
⣿⣷⡀⠀⠀⠀⠀⠠⠭⣍⡉⢩⣥⡤⠥⣤⡶⣒⠀⠀⠀⠀⠀⢰⣿⣿
⣿⣿⡽⡄⠀⠀⠀⢿⣿⣆⣿⣧⢡⣾⣿⡇⣾⣿⡇⠀⠀⠀⠀⣿⡇⠃
⣿⣿⣷⣻⣆⢄⠀⠈⠉⠉⠛⠛⠘⠛⠛⠛⠙⠛⠁⠀⠀⠀⠀⣿⡇⢸
⢞⣿⣿⣷⣝⣷⣝⠦⡀⠀⠀⠀⠀⠀⠀⠀⡀⢀⠀⠀⠀⠀⠀⠛⣿⠈
⣦⡑⠛⣟⢿⡿⣿⣷⣝⢧⡀⠀⠀⣶⣸⡇⣿⢸⣧⠀⠀⠀⠀⢸⡿⡆
⣿⣿⣷⣮⣭⣍⡛⠻⢿⣷⠿⣶⣶⣬⣬⣁⣉⣀⣀⣁⡤⢴⣺⣾⣽⡇
*/
Node* _head = head;
head=head->next;
delete _head;
@@ -393,4 +381,4 @@ namespace task7 {
}
head = result;
}
}
}

10
task8.h
View File

@@ -12,10 +12,10 @@ namespace task8 {
Node* next;
};
Node* newNode(int key); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
Node* rand_list(int size); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void print_list(Node* head); //<2F><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void cycle(Node*&head, int offset); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Node* newNode(int key);
Node* rand_list(int size);
void print_list(Node* head);
void cycle(Node*&head, int offset);
int init()
{
@@ -111,4 +111,4 @@ namespace task8 {
prv->next = nullptr;
}
}
}