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

Commit 517b799

Browse files
authored
Merge pull request #587 from Arkadiy-Git/lab1120
Merge remote-tracking branch 'origin/lab1120' into lab21,25-31
2 parents 12ae673 + 5391038 commit 517b799

File tree

29 files changed

+1193
-2
lines changed

29 files changed

+1193
-2
lines changed

students/23K0155/23K0155-p10/src/main/java/ru/mirea/practice/s23k0155/Задание

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
Задание 2. (45%)
88
Напишите класс SortingStudentsByGPA (может у вас называться Tester
9-
или Main, так как содержит функцию main()) создайте поле как массив
9+
или ru.mirea.practice.s0000001.task1.Main, так как содержит функцию main()) создайте поле как массив
1010
объектов Student с названием iDNumber, вы можете использовать как массив,
1111
так и и ArrayList или TreeSet для хранения данных о студентах
1212
Добавьте методы класса: 1) заполнения массива setArray() 2) метод для

students/23K0155/23K0155-p13/src/main/java/ru/mirea/practice/s23k0155/Задание

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
Задание 2. (45%)
88
Напишите класс SortingStudentsByGPA (может у вас называться Tester
9-
или Main, так как содержит функцию main()) создайте поле как массив
9+
или ru.mirea.practice.s0000001.task1.Main, так как содержит функцию main()) создайте поле как массив
1010
объектов Student с названием iDNumber, вы можете использовать как массив,
1111
так и и ArrayList или TreeSet для хранения данных о студентах
1212
Добавьте методы класса: 1) заполнения массива setArray() 2) метод для
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>23K1226</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K1226-p21</artifactId>
12+
<description> </description>
13+
</project>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package ru.mirea.practice.s0000001.task1;
2+
3+
import java.io.File;
4+
import java.util.ArrayList;
5+
import java.util.HashSet;
6+
import java.util.HashMap;
7+
import java.util.List;
8+
import java.util.Map;
9+
import java.util.Set;
10+
import java.util.Scanner;
11+
12+
class Solution<T, K, V> {
13+
T t;
14+
K k;
15+
V v;
16+
17+
public Solution(T t, K k, V v) {
18+
this.t = t;
19+
this.k = k;
20+
this.v = v;
21+
}
22+
23+
public static <T> List<T> convertArrayToList(T[] array) {
24+
return new ArrayList<>(List.of(array));
25+
}
26+
27+
public static <T> Object[] storeData(T... data) {
28+
return data;
29+
}
30+
31+
public static <T> T getElementByIndex(T[] array, int index) {
32+
return array[index];
33+
}
34+
35+
public static List<String> listDirectoryContents(String directoryPath) {
36+
File folder = new File(directoryPath);
37+
File[] listOfFiles = folder.listFiles();
38+
List<String> fileList = new ArrayList<>();
39+
if (listOfFiles != null) {
40+
for (File file : listOfFiles) {
41+
if (file.isFile()) {
42+
fileList.add(file.getName());
43+
}
44+
}
45+
}
46+
return fileList;
47+
}
48+
49+
public static <T> List<T> newArrayList(T... items) {
50+
return new ArrayList<>(List.of(items));
51+
}
52+
53+
public static <T> Set<T> newHashSet(T... items) {
54+
return new HashSet<>(Set.of(items));
55+
}
56+
57+
public static <K, V> Map<K, V> newHashMap(Map.Entry<K, V>... entries) {
58+
Map<K, V> map = new HashMap<>();
59+
for (Map.Entry<K, V> entry : entries) {
60+
map.put(entry.getKey(), entry.getValue());
61+
}
62+
return map;
63+
}
64+
65+
public static void main(String[] args) {
66+
try (Scanner scanner = new Scanner(System.in)) {
67+
String[] array = scanner.nextLine().split(" ");
68+
List<String> list = convertArrayToList(array);
69+
list.forEach(System.out::println);
70+
}
71+
}
72+
}
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>23K1226</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K1226-p25</artifactId>
12+
<description> </description>
13+
</project>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package ru.mirea.practice.s0000001.task1;
2+
3+
import java.util.Scanner;
4+
import java.util.regex.Pattern;
5+
import java.util.regex.Matcher;
6+
7+
public final class RegalTasks {
8+
9+
private RegalTasks() {
10+
}
11+
12+
public static void main(String[] args) {
13+
try (Scanner scanner = new Scanner(System.in)) {
14+
15+
System.out.println("1. Введите строку для разбиения по пробелам:");
16+
String input = scanner.nextLine();
17+
String[] splitResult = input.split("\\s+");
18+
for (String part : splitResult) {
19+
System.out.println("Часть строки: " + part);
20+
}
21+
22+
System.out.println("\n2. Проверьте, соответствует ли строка 'abcdefghijklmnopqrstuv18340':");
23+
input = scanner.nextLine();
24+
boolean isExactMatch = input.matches("abcdefghijklmnopqrstuv18340");
25+
System.out.println("Соответствует: " + isExactMatch);
26+
27+
System.out.println("\n3. Введите текст для извлечения цен в USD, RUB, или EU:");
28+
input = scanner.nextLine();
29+
Matcher priceMatcher = Pattern.compile("\\b\\d+\\.\\d{2}\\s?(USD|RUB|EU)\\b").matcher(input);
30+
while (priceMatcher.find()) {
31+
System.out.println("Найдена цена: " + priceMatcher.group());
32+
}
33+
34+
System.out.println("\n4. Введите текст, чтобы проверить, есть ли числа без знака '+':");
35+
input = scanner.nextLine();
36+
boolean hasNumberWithoutPlus = Pattern.compile("\\b\\d+(?!\\+)").matcher(input).find();
37+
System.out.println("Числа без знака '+': " + hasNumberWithoutPlus);
38+
39+
System.out.println("\n5. Проверьте, является ли строка датой в формате dd/mm/yyyy:");
40+
input = scanner.nextLine();
41+
boolean isValidDate = input.matches("^(0[1-9]|[12]\\d|3[01])/(0[1-9]|1[0-2])/((19\\d{2})|([2-9]\\d{3}))$");
42+
System.out.println("Допустимый формат даты: " + isValidDate);
43+
44+
System.out.println("\n6. Введите email для проверки на корректность:");
45+
input = scanner.nextLine();
46+
boolean isValidEmail = input.matches("^[\\w.!#$%&'*+/=?^_`{|}~-]+@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*$");
47+
System.out.println("Корректный email: " + isValidEmail);
48+
49+
System.out.println("\n7. Введите пароль для проверки его надежности:");
50+
input = scanner.nextLine();
51+
boolean isStrongPassword = input.matches("^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[A-Za-z\\d_]{8,}$");
52+
System.out.println("Надежный пароль: " + isStrongPassword);
53+
54+
}
55+
}
56+
}
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>23K1226</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K1226-p26</artifactId>
12+
<description> </description>
13+
</project>
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package ru.mirea.practice.s0000001.task1;
2+
3+
import java.util.Iterator;
4+
import java.util.List;
5+
import java.util.ArrayList;
6+
import java.util.Stack;
7+
import java.util.Scanner;
8+
9+
public final class Main {
10+
11+
private Main() {
12+
// Приватный конструктор для предотвращения создания экземпляра утилитного класса
13+
}
14+
15+
public static void main(String[] args) {
16+
try (Scanner scanner = new Scanner(System.in)) {
17+
18+
System.out.println("Введите размер массива:");
19+
int size = scanner.nextInt();
20+
int[] array = new int[size];
21+
System.out.println("Введите элементы массива:");
22+
for (int i = 0; i < size; i++) {
23+
array[i] = scanner.nextInt();
24+
}
25+
26+
invertArrayUsingStack(array);
27+
28+
System.out.println("Инвертированный массив:");
29+
for (int num : array) {
30+
System.out.print(num + " ");
31+
}
32+
System.out.println();
33+
34+
CustomList<Integer> customList = new CustomList<>();
35+
customList.add(1);
36+
customList.add(2);
37+
customList.add(3);
38+
System.out.println("Элементы CustomList с использованием итератора:");
39+
CustomIterator<Integer> iterator = customList.iterator();
40+
while (iterator.hasNext()) {
41+
System.out.print(iterator.next() + " ");
42+
}
43+
System.out.println();
44+
}
45+
}
46+
47+
public static void invertArrayUsingStack(int[] array) {
48+
Stack<Integer> stack = new Stack<>();
49+
for (int value : array) {
50+
stack.push(value);
51+
}
52+
for (int i = 0; i < array.length; i++) {
53+
array[i] = stack.pop();
54+
}
55+
}
56+
57+
static class CustomList<T> implements Iterable<T> {
58+
private List<T> elements;
59+
60+
public CustomList() {
61+
elements = new ArrayList<>();
62+
}
63+
64+
public void add(T element) {
65+
elements.add(element);
66+
}
67+
68+
@Override
69+
public CustomIterator<T> iterator() {
70+
return new CustomIterator<>(elements);
71+
}
72+
}
73+
74+
static class CustomIterator<T> implements Iterator<T> {
75+
private List<T> list;
76+
private int index = 0;
77+
78+
public CustomIterator(List<T> list) {
79+
this.list = list;
80+
}
81+
82+
@Override
83+
public boolean hasNext() {
84+
return index < list.size();
85+
}
86+
87+
@Override
88+
public T next() {
89+
return list.get(index++);
90+
}
91+
}
92+
}
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>23K1226</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K1226-p27</artifactId>
12+
<description> </description>
13+
</project>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package ru.mirea.practice.s0000001.task1;
2+
3+
class HashTable {
4+
private static final int SIZE = 10;
5+
private Entry[] table;
6+
7+
public HashTable() {
8+
table = new Entry[SIZE];
9+
}
10+
11+
private static class Entry {
12+
String key;
13+
String value;
14+
Entry next;
15+
16+
Entry(String key, String value) {
17+
this.key = key;
18+
this.value = value;
19+
this.next = null;
20+
}
21+
}
22+
23+
public int hashtabHash(String key) {
24+
return key.hashCode() % SIZE;
25+
}
26+
27+
public void hashtabInit() {
28+
for (int i = 0; i < SIZE; i++) {
29+
table[i] = null;
30+
}
31+
}
32+
33+
public void hashtabAdd(String key, String value) {
34+
int index = hashtabHash(key);
35+
Entry newEntry = new Entry(key, value);
36+
if (table[index] == null) {
37+
table[index] = newEntry;
38+
} else {
39+
Entry current = table[index];
40+
while (current.next != null) {
41+
current = current.next;
42+
}
43+
current.next = newEntry;
44+
}
45+
}
46+
47+
public String hashtabLookup(String key) {
48+
int index = hashtabHash(key);
49+
Entry current = table[index];
50+
while (current != null) {
51+
if (current.key.equals(key)) {
52+
return current.value;
53+
}
54+
current = current.next;
55+
}
56+
return null;
57+
}
58+
59+
public void hashtabDelete(String key) {
60+
int index = hashtabHash(key);
61+
Entry current = table[index];
62+
Entry previous = null;
63+
while (current != null) {
64+
if (current.key.equals(key)) {
65+
if (previous == null) {
66+
table[index] = current.next;
67+
} else {
68+
previous.next = current.next;
69+
}
70+
return;
71+
}
72+
previous = current;
73+
current = current.next;
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)