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

Commit 16b0232

Browse files
committed
Lab26-29
1 parent 4b0731a commit 16b0232

File tree

19 files changed

+677
-54
lines changed

19 files changed

+677
-54
lines changed
Lines changed: 65 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,72 @@
11
package ru.mirea.practice.s0000001;
2-
import java.util.regex.*;
2+
3+
import java.util.regex.Pattern;
4+
import java.util.regex.Matcher;
35
import java.util.Scanner;
6+
47
// Задания№1-5
5-
public class Main {
8+
9+
public final class Main {
10+
11+
private Main() {
12+
throw new UnsupportedOperationException("Utility class");
13+
}
14+
615
public static void main(String[] args) {
7-
Scanner sc = new Scanner(System.in);
8-
System.out.println("Введите строку:");
9-
String input = sc.nextLine();
10-
11-
System.out.println("Пожалуйста, выберите действие:");
12-
System.out.println("1. Проверить строку на соответствие шаблону 'abcdefghijklmnopqrstuv18340'");
13-
System.out.println("2. Извлечь цены в USD, RUB, EUR");
14-
System.out.println("3. Проверить наличие чисел без знака '+'");
15-
System.out.println("4. Проверить, является ли строка датой в формате dd/mm/yyyy");
16-
System.out.println("5. Проверить корректность e-mail");
17-
System.out.println("6. Проверить надежность пароля");
18-
19-
int choice = sc.nextInt();
20-
sc.nextLine(); // Очистка ввода
21-
switch (choice) {
22-
case 1:
23-
Pattern p1 = Pattern.compile("abcdefghijklmnopqrstuv18340");
24-
boolean match1 = p1.matcher(input).matches();
25-
System.out.println(match1 ? "Соответствует шаблону^'^" : "Не соответствует шаблону^-^");
26-
break;
27-
case 2:
28-
Pattern p2 = Pattern.compile("\\d+\\.\\d{2}\\s?(USD|RUB|EUR)");
29-
Matcher m2 = p2.matcher(input);
30-
while (m2.find()) {
31-
System.out.println("Цена: " + m2.group());
32-
}
33-
break;
34-
case 3:
35-
Pattern p3 = Pattern.compile("\\d(?!\\+)");
36-
Matcher m3 = p3.matcher(input);
37-
while (m3.find()) {
38-
System.out.println("Число без '+': " + m3.group());
39-
}
40-
break;
41-
case 4:
42-
Pattern p4 = Pattern.compile("^(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[0-2])/(19\\d{2}|[2-9]\\d{3})$");
43-
boolean match4 = p4.matcher(input).matches();
44-
System.out.println(match4 ? "Корректная дата" : "Некорректная дата:(");
45-
break;
46-
case 5:
47-
Pattern p5 = Pattern.compile("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}$");
48-
boolean match5 = p5.matcher(input).matches();
49-
System.out.println(match5 ? "Корректный e-mail" : "Некорректный e-mail:(");
50-
break;
51-
case 6:
52-
Pattern p6 = Pattern.compile("^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d_]{8,}$");
53-
boolean match6 = p6.matcher(input).matches();
54-
System.out.println(match6 ? "Надежный пароль" : "Ненадежный пароль:(");
55-
break;
56-
default:
57-
System.out.println("Некорректный выбор:(");
16+
try (Scanner sc = new Scanner(System.in)) {
17+
System.out.println("Пожалуйста, выберите действие:");
18+
System.out.println("1. Проверить строку на соответствие шаблону 'abcdefghijklmnopqrstuv18340'");
19+
System.out.println("2. Извлечь цены в USD, RUB, EUR");
20+
System.out.println("3. Проверить наличие чисел без знака '+'");
21+
System.out.println("4. Проверить, является ли строка датой в формате dd/mm/yyyy");
22+
System.out.println("5. Проверить корректность e-mail");
23+
System.out.println("6. Проверить надежность пароля");
24+
25+
int choice = sc.nextInt();
26+
sc.nextLine();
27+
28+
System.out.println("Введите строку:");
29+
final String input = sc.nextLine();
30+
31+
switch (choice) {
32+
case 1:
33+
Pattern p1 = Pattern.compile("abcdefghijklmnopqrstuv18340");
34+
boolean match1 = p1.matcher(input).matches();
35+
System.out.println(match1 ? "Соответствует шаблону^'^" : "Не соответствует шаблону^-^");
36+
break;
37+
case 2:
38+
Pattern p2 = Pattern.compile("\\d+\\.\\d{2}\\s?(USD|RUB|EUR)");
39+
Matcher m2 = p2.matcher(input);
40+
while (m2.find()) {
41+
System.out.println("Цена: " + m2.group());
42+
}
43+
break;
44+
case 3:
45+
Pattern p3 = Pattern.compile("\\d(?!\\+)");
46+
Matcher m3 = p3.matcher(input);
47+
while (m3.find()) {
48+
System.out.println("Число без '+': " + m3.group());
49+
}
50+
break;
51+
case 4:
52+
Pattern p4 = Pattern.compile("^(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[0-2])/(19\\d{2}|[2-9]\\d{3})$");
53+
boolean match4 = p4.matcher(input).matches();
54+
System.out.println(match4 ? "Корректная дата" : "Некорректная дата:(");
55+
break;
56+
case 5:
57+
Pattern p5 = Pattern.compile("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}$");
58+
boolean match5 = p5.matcher(input).matches();
59+
System.out.println(match5 ? "Корректный e-mail" : "Некорректный e-mail:(");
60+
break;
61+
case 6:
62+
Pattern p6 = Pattern.compile("^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d_]{8,}$");
63+
boolean match6 = p6.matcher(input).matches();
64+
System.out.println(match6 ? "Надежный пароль" : "Ненадежный пароль:(");
65+
break;
66+
default:
67+
System.out.println("Некорректный выбор:(");
68+
break;
69+
}
5870
}
59-
sc.close();
6071
}
6172
}

students/23K0565/23K0565-p26/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="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>23K0565</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0565-p26</artifactId>
12+
<description>26 практическая</description>
13+
</project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package ru.mirea.practice.s0000001.n1;
2+
3+
import java.util.Stack;
4+
5+
public final class InvertArray {
6+
private InvertArray() {
7+
}
8+
9+
public static int[] invert(int[] arr) {
10+
Stack<Integer> stack = new Stack<>();
11+
for (int num : arr) {
12+
stack.push(num);
13+
}
14+
15+
for (int i = 0; i < arr.length; i++) {
16+
arr[i] = stack.pop();
17+
}
18+
19+
return arr;
20+
}
21+
22+
public static void main(String[] args) {
23+
int[] data = {1, 2, 3, 4, 5};
24+
data = invert(data);
25+
for (int num : data) {
26+
System.out.print(num + " ");
27+
}
28+
}
29+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package ru.mirea.practice.s0000001.n2;
2+
3+
import java.util.Iterator;
4+
import java.util.List;
5+
6+
public class CusIterator<T> implements Iterator<T> {
7+
private List<T> lst;
8+
private int idx;
9+
10+
public CusIterator(List<T> lst) {
11+
this.lst = lst;
12+
this.idx = 0;
13+
}
14+
15+
@Override
16+
public boolean hasNext() {
17+
return idx < lst.size();
18+
}
19+
20+
@Override
21+
public T next() {
22+
return lst.get(idx++);
23+
}
24+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package ru.mirea.practice.s0000001.n2;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public final class ListD {
7+
private ListD() {
8+
}
9+
10+
public static void main(String[] args) {
11+
List<Integer> nums = new ArrayList<>();
12+
nums.add(10);
13+
nums.add(20);
14+
nums.add(30);
15+
16+
CusIterator<Integer> iter = new CusIterator<>(nums);
17+
18+
while (iter.hasNext()) {
19+
System.out.println(iter.next());
20+
}
21+
}
22+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package ru.mirea.practice.s0000001.n3;
2+
3+
import java.util.Iterator;
4+
5+
public class CusIterator<T> implements Iterator<T> {
6+
private CusList<T> lst;
7+
private int idx;
8+
9+
public CusIterator(CusList<T> lst) {
10+
this.lst = lst;
11+
this.idx = 0;
12+
}
13+
14+
@Override
15+
public boolean hasNext() {
16+
return idx < lst.size();
17+
}
18+
19+
@Override
20+
public T next() {
21+
return lst.get(idx++);
22+
}
23+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package ru.mirea.practice.s0000001.n3;
2+
3+
import java.util.Iterator;
4+
5+
public class CusList<T> implements Iterable<T> {
6+
private Object[] elements;
7+
private int size;
8+
9+
public CusList(int capacity) {
10+
elements = new Object[capacity];
11+
size = 0;
12+
}
13+
14+
public void add(T item) {
15+
if (size < elements.length) {
16+
elements[size++] = item;
17+
} else {
18+
throw new IndexOutOfBoundsException("Список заполнен(");
19+
}
20+
}
21+
22+
public T get(int index) {
23+
if (index >= 0 && index < size) {
24+
return (T) elements[index];
25+
} else {
26+
throw new IndexOutOfBoundsException("Некорректный индекс:(");
27+
}
28+
}
29+
30+
public int size() {
31+
return size;
32+
}
33+
34+
@Override
35+
public Iterator<T> iterator() {
36+
return new CusIterator<>(this);
37+
}
38+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package ru.mirea.practice.s0000001.n3;
2+
3+
public final class ListDemo {
4+
private ListDemo() {
5+
}
6+
7+
public static void main(String[] args) {
8+
CusList<Integer> nums = new CusList<>(5);
9+
nums.add(10);
10+
nums.add(20);
11+
nums.add(30);
12+
13+
for (int num : nums) {
14+
System.out.println(num);
15+
}
16+
}
17+
}

students/23K0565/23K0565-p27/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="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>23K0565</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0565-p27</artifactId>
12+
<description>27 практическая</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.s0000001.n1;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
public final class Hashtab {
7+
private static final int SIZE = 10;
8+
private static Map<Integer, String> hTable;
9+
10+
private Hashtab() {
11+
}
12+
13+
public static int hashtabHash(String key) {
14+
return Math.abs(key.hashCode() % SIZE);
15+
}
16+
17+
public static void hashtabInit() {
18+
hTable = new HashMap<>();
19+
}
20+
21+
public static void hashtabAdd(String key, String value) {
22+
int idx = hashtabHash(key);
23+
hTable.put(idx, value);
24+
}
25+
26+
public static String hashtabLookup(String key) {
27+
int idx = hashtabHash(key);
28+
return hTable.get(idx);
29+
}
30+
31+
public static void hashtabDelete(String key) {
32+
int idx = hashtabHash(key);
33+
hTable.remove(idx);
34+
}
35+
36+
public static void main(String[] args) {
37+
hashtabInit();
38+
39+
hashtabAdd("ключ1", "значение1");
40+
hashtabAdd("ключ2", "значение2");
41+
hashtabAdd("ключ3", "значение3");
42+
hashtabAdd("ключ4", "значение4");
43+
hashtabAdd("ключ5", "значение5");
44+
hashtabAdd("ключ6", "значение6");
45+
hashtabAdd("ключ7", "значение7");
46+
hashtabAdd("ключ8", "значение8");
47+
hashtabAdd("ключ9", "значение9");
48+
hashtabAdd("ключ10", "значение10");
49+
50+
System.out.println("Поиск ключа 'ключ3'..: " + hashtabLookup("ключ3"));
51+
52+
hashtabDelete("ключ3");
53+
System.out.println("После удаления ключа 'ключ3': " + hashtabLookup("ключ3"));
54+
}
55+
}

0 commit comments

Comments
 (0)