Skip to content
This repository was archived by the owner on Dec 28, 2024. It is now read-only.

Commit 224d84d

Browse files
committed
21-24
1 parent 44c31f5 commit 224d84d

File tree

15 files changed

+444
-0
lines changed

15 files changed

+444
-0
lines changed

students/23K0375/23K0375-p21/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<artifactId>23K0375</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0375-p21</artifactId>
12+
<description>Массивы</description>
13+
</project>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package ru.mirea.practice.s23k0375.task1;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public abstract class Sol {
7+
8+
// Метод для конвертации массива строк в список
9+
public static List<String> convertStringArrayToList(String[] array) {
10+
List<String> list = new ArrayList<>();
11+
for (String element : array) {
12+
list.add(element);
13+
}
14+
return list;
15+
}
16+
17+
// Метод для конвертации массива чисел в список
18+
public static List<Integer> convertIntegerArrayToList(Integer[] array) {
19+
List<Integer> list = new ArrayList<>();
20+
for (Integer element : array) {
21+
list.add(element);
22+
}
23+
return list;
24+
}
25+
26+
public static void main(String[] args) {
27+
// Пример использования метода для строк
28+
String[] stringArray = {"apple", "banana", "cherry"};
29+
List<String> stringList = convertStringArrayToList(stringArray);
30+
System.out.println("Список строк: " + stringList);
31+
32+
// Пример использования метода для чисел
33+
Integer[] integerArray = {1, 2, 3, 4, 5};
34+
List<Integer> integerList = convertIntegerArrayToList(integerArray);
35+
System.out.println("Список чисел: " + integerList);
36+
}
37+
}

students/23K0375/23K0375-p22/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<artifactId>23K0375</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0375-p22</artifactId>
12+
<description>дисплеи</description>
13+
</project>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package ru.mirea.practice.s23k0375.task1;
2+
3+
import java.util.Scanner;
4+
import java.util.Stack;
5+
6+
public abstract class RpnCalc {
7+
8+
public static double evaluate(String expression) {
9+
Stack<Double> stack = new Stack<>();
10+
11+
// Разделяем входную строку на элементы
12+
String[] tokens = expression.split(" ");
13+
14+
for (String token : tokens) {
15+
switch (token) {
16+
case "+":
17+
stack.push(stack.pop() + stack.pop());
18+
break;
19+
case "-":
20+
double subtrahend = stack.pop();
21+
double minuend = stack.pop();
22+
stack.push(minuend - subtrahend);
23+
break;
24+
case "*":
25+
stack.push(stack.pop() * stack.pop());
26+
break;
27+
case "/":
28+
double divisor = stack.pop();
29+
double dividend = stack.pop();
30+
stack.push(dividend / divisor);
31+
break;
32+
default:
33+
// Если токен не оператор, то предполагаем, что это число
34+
stack.push(Double.parseDouble(token));
35+
break;
36+
}
37+
}
38+
39+
// Результат будет единственным элементом в стеке
40+
return stack.pop();
41+
}
42+
43+
public static void main(String[] args) {
44+
// Используем try-with-resources для безопасного закрытия Scanner
45+
try (Scanner scanner = new Scanner(System.in)) {
46+
System.out.print("Введите выражение в обратной польской нотации (RPN): ");
47+
48+
String expression = scanner.nextLine();
49+
50+
if (expression != null && !expression.trim().isEmpty()) {
51+
try {
52+
double result = evaluate(expression);
53+
System.out.println("Результат: " + result);
54+
} catch (Exception e) {
55+
System.out.println("Ошибка: " + e.getMessage());
56+
}
57+
} else {
58+
System.out.println("Вы не ввели выражение.");
59+
}
60+
}
61+
}
62+
}

students/23K0375/23K0375-p23/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<artifactId>23K0375</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0375-p23</artifactId>
12+
<description>Массивы</description>
13+
</project>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package ru.mirea.practice.s23k0375.task1;
2+
3+
public class ArrayQueue {
4+
private Object[] elements;
5+
private int head;
6+
private int tail;
7+
private int size;
8+
9+
public ArrayQueue(int capacity) {
10+
elements = new Object[capacity];
11+
head = 0;
12+
tail = 0;
13+
size = 0;
14+
}
15+
16+
public void enqueue(Object element) {
17+
if (size == elements.length) {
18+
throw new IllegalStateException("Очередь переполнена");
19+
}
20+
elements[tail] = element;
21+
tail = (tail + 1) % elements.length;
22+
size++;
23+
}
24+
25+
public Object element() {
26+
if (size == 0) {
27+
throw new IllegalStateException("Очередь пуста");
28+
}
29+
return elements[head];
30+
}
31+
32+
public Object dequeue() {
33+
if (size == 0) {
34+
throw new IllegalStateException("Очередь пуста");
35+
}
36+
Object result = elements[head];
37+
head = (head + 1) % elements.length;
38+
size--;
39+
return result;
40+
}
41+
42+
public int size() {
43+
return size;
44+
}
45+
46+
public boolean isEmpty() {
47+
return size == 0;
48+
}
49+
50+
public void clear() {
51+
head = 0;
52+
tail = 0;
53+
size = 0;
54+
}
55+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package ru.mirea.practice.s23k0375.task1;
2+
3+
public class ArrayQueueAdt {
4+
private Object[] elements;
5+
private int head;
6+
private int tail;
7+
private int size;
8+
9+
public ArrayQueueAdt(int capacity) {
10+
elements = new Object[capacity];
11+
head = 0;
12+
tail = 0;
13+
size = 0;
14+
}
15+
16+
// Добавить элемент в очередь
17+
public void enqueue(Object element) {
18+
if (size == elements.length) {
19+
throw new IllegalStateException("Очередь переполнена");
20+
}
21+
elements[tail] = element;
22+
tail = (tail + 1) % elements.length;
23+
size++;
24+
}
25+
26+
// Первый элемент в очереди
27+
public Object element() {
28+
if (size == 0) {
29+
throw new IllegalStateException("Очередь пуста");
30+
}
31+
return elements[head];
32+
}
33+
34+
// Удалить и вернуть первый элемент
35+
public Object dequeue() {
36+
if (size == 0) {
37+
throw new IllegalStateException("Очередь пуста");
38+
}
39+
Object result = elements[head];
40+
head = (head + 1) % elements.length;
41+
size--;
42+
return result;
43+
}
44+
45+
// Текущий размер очереди
46+
public int size() {
47+
return size;
48+
}
49+
50+
// Является ли очередь пустой
51+
public boolean isEmpty() {
52+
return size == 0;
53+
}
54+
55+
// Удалить все элементы
56+
public void clear() {
57+
head = 0;
58+
tail = 0;
59+
size = 0;
60+
}
61+
}
62+
// Тесты для классов
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package ru.mirea.practice.s23k0375.task1;
2+
3+
public abstract class ArrayQueueModule {
4+
private static final int DEFAULT_CAPACITY = 10;
5+
private static Object[] elements;
6+
private static int head;
7+
private static int tail;
8+
private static int size;
9+
10+
static {
11+
elements = new Object[DEFAULT_CAPACITY];
12+
head = 0;
13+
tail = 0;
14+
size = 0;
15+
}
16+
17+
// Добавить элемент в очередь
18+
public static void enqueue(Object element) {
19+
// Предусловие: Очередь не переполнена
20+
if (size == elements.length) {
21+
throw new IllegalStateException("Очередь переполнена");
22+
}
23+
elements[tail] = element;
24+
tail = (tail + 1) % elements.length;
25+
size++;
26+
// Постусловие: Элемент добавлен
27+
}
28+
29+
// Первый элемент в очереди
30+
public static Object element() {
31+
// Предусловие: Очередь не пуста
32+
if (size == 0) {
33+
throw new IllegalStateException("Очередь пуста");
34+
}
35+
return elements[head];
36+
// Постусловие: Возвращает первый элемент без удаления
37+
}
38+
39+
// Удалить и вернуть первый элемент
40+
public static Object dequeue() {
41+
// Предусловие: Очередь не пуста
42+
if (size == 0) {
43+
throw new IllegalStateException("Очередь пуста");
44+
}
45+
Object result = elements[head];
46+
head = (head + 1) % elements.length;
47+
size--;
48+
// Постусловие: Первый элемент удален и возвращен
49+
return result;
50+
}
51+
52+
// Текущий размер очереди
53+
public static int size() {
54+
// Постусловие: Возвращает количество элементов
55+
return size;
56+
}
57+
58+
// Является ли очередь пустой
59+
public static boolean isEmpty() {
60+
// Постусловие: Возвращает true, если очередь пуста
61+
return size == 0;
62+
}
63+
64+
// Удалить все элементы
65+
public static void clear() {
66+
head = 0;
67+
tail = 0;
68+
size = 0;
69+
// Постусловие: Очередь пуста
70+
}
71+
}
72+
73+
// Класс ArrayQueueAdt
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package ru.mirea.practice.s23k0375.task1;
2+
3+
public abstract class ArrayQueueTest {
4+
public static void main(String[] args) {
5+
// Тест для ArrayQueueModule
6+
ArrayQueueModule.enqueue(1);
7+
ArrayQueueModule.enqueue(2);
8+
System.out.println(ArrayQueueModule.element()); // Вывод: 1
9+
System.out.println(ArrayQueueModule.dequeue()); // Вывод: 1
10+
System.out.println(ArrayQueueModule.size()); // Вывод: 1
11+
System.out.println(ArrayQueueModule.isEmpty()); // Вывод: false
12+
ArrayQueueModule.clear();
13+
System.out.println(ArrayQueueModule.isEmpty()); // Вывод: true
14+
15+
// Тест для ArrayQueueAdt
16+
ArrayQueueAdt queueAdt = new ArrayQueueAdt(5);
17+
queueAdt.enqueue(3);
18+
queueAdt.enqueue(4);
19+
System.out.println(queueAdt.element()); // Вывод: 3
20+
System.out.println(queueAdt.dequeue()); // Вывод: 3
21+
System.out.println(queueAdt.size()); // Вывод: 1
22+
System.out.println(queueAdt.isEmpty()); // Вывод: false
23+
queueAdt.clear();
24+
System.out.println(queueAdt.isEmpty()); // Вывод: true
25+
26+
// Тест для ArrayQueue
27+
ArrayQueue queue = new ArrayQueue(5);
28+
queue.enqueue(5);
29+
queue.enqueue(6);
30+
System.out.println(queue.element()); // Вывод: 5
31+
System.out.println(queue.dequeue()); // Вывод: 5
32+
System.out.println(queue.size()); // Вывод: 1
33+
System.out.println(queue.isEmpty()); // Вывод: false
34+
queue.clear();
35+
System.out.println(queue.isEmpty()); // Вывод: true
36+
}
37+
}

students/23K0375/23K0375-p24/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<artifactId>23K0375</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0375-p24</artifactId>
12+
<description>Массивы</description>
13+
</project>

0 commit comments

Comments
 (0)