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

Commit 13994c0

Browse files
committed
25-32
1 parent bdd7561 commit 13994c0

File tree

21 files changed

+734
-0
lines changed

21 files changed

+734
-0
lines changed

students/23K0375/23K0375-p25/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-p25</artifactId>
12+
<description>Массивы</description>
13+
</project>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package ru.mirea.practice.s23k0375.task1;
2+
3+
import java.util.Scanner;
4+
5+
public final class StrTest {
6+
7+
private StrTest() {
8+
throw new UnsupportedOperationException("Утилитный класс не должен быть создан");
9+
}
10+
11+
public static void main(String[] args) {
12+
try (Scanner sc = new Scanner(System.in)) {
13+
System.out.println("Введите строку:");
14+
final String str = sc.nextLine();
15+
16+
System.out.println("Выберите операцию:");
17+
System.out.println("1. Разбить строку на слова");
18+
System.out.println("2. Заменить все пробелы на дефисы");
19+
System.out.println("3. Найти все числа в строке");
20+
System.out.println("4. Удалить все цифры из строки");
21+
22+
int option = sc.nextInt();
23+
sc.nextLine();
24+
25+
switch (option) {
26+
case 1:
27+
String[] words = str.split("\\s+");
28+
System.out.println("Разбитые слова:");
29+
for (String word : words) {
30+
System.out.println(word);
31+
}
32+
break;
33+
case 2:
34+
String rep = str.replaceAll("\\s+", "-");
35+
System.out.println("Строка с замененными пробелами:");
36+
System.out.println(rep);
37+
break;
38+
case 3:
39+
String[] nums = str.split("\\D+");
40+
System.out.println("Найденные числа:");
41+
for (String num : nums) {
42+
if (!num.isEmpty()) {
43+
System.out.println(num);
44+
}
45+
}
46+
break;
47+
case 4:
48+
String noDigits = str.replaceAll("\\d", "");
49+
System.out.println("Строка без цифр:");
50+
System.out.println(noDigits);
51+
break;
52+
default:
53+
System.out.println("Неверный выбор");
54+
break;
55+
}
56+
}
57+
}
58+
}

students/23K0375/23K0375-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: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-p26</artifactId>
12+
<description>Массивы</description>
13+
</project>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package ru.mirea.practice.s23k0375.task1;
2+
3+
import java.util.Stack;
4+
5+
public final class InvArr {
6+
7+
private InvArr() {
8+
throw new UnsupportedOperationException("Utility class");
9+
}
10+
11+
public static void invertArray(int[] arr) {
12+
Stack<Integer> stack = new Stack<>();
13+
14+
for (int num : arr) {
15+
stack.push(num);
16+
}
17+
18+
int i = 0;
19+
for (; i < arr.length; i++) {
20+
arr[i] = stack.pop();
21+
}
22+
}
23+
24+
public static void main(String[] args) {
25+
int[] array = {11, 23, 36, 42, 58, 68, 75, 87, 99};
26+
27+
System.out.println("Исходный массив:");
28+
for (int num : array) {
29+
System.out.print(num + " ");
30+
}
31+
System.out.println();
32+
33+
invertArray(array);
34+
35+
System.out.println("Инвертированный массив:");
36+
for (int num : array) {
37+
System.out.print(num + " ");
38+
}
39+
}
40+
}

students/23K0375/23K0375-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: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-p27</artifactId>
12+
<description>Массивы</description>
13+
</project>
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+
import java.util.LinkedList;
4+
5+
public class Hashtab {
6+
private static final int SIZE = 10;
7+
private LinkedList<Entry>[] table;
8+
9+
static class Entry {
10+
String key;
11+
String value;
12+
13+
Entry(String key, String value) {
14+
this.key = key;
15+
this.value = value;
16+
}
17+
}
18+
19+
public void hashtabInit() {
20+
table = new LinkedList[SIZE];
21+
for (int i = 0; i < SIZE; i++) {
22+
table[i] = new LinkedList<>();
23+
}
24+
}
25+
26+
public int hashtabHash(String key) {
27+
return Math.abs(key.hashCode() % SIZE);
28+
}
29+
30+
public void hashtabAdd(String key, String value) {
31+
int index = hashtabHash(key);
32+
for (Entry entry : table[index]) {
33+
if (entry.key.equals(key)) {
34+
entry.value = value;
35+
return;
36+
}
37+
}
38+
table[index].add(new Entry(key, value));
39+
}
40+
41+
public String hashtabLookup(String key) {
42+
int index = hashtabHash(key);
43+
for (Entry entry : table[index]) {
44+
if (entry.key.equals(key)) {
45+
return entry.value;
46+
}
47+
}
48+
return null;
49+
}
50+
51+
public void hashtabDelete(String key) {
52+
int index = hashtabHash(key);
53+
table[index].removeIf(entry -> entry.key.equals(key));
54+
}
55+
56+
public static void main(String[] args) {
57+
Hashtab hashtab = new Hashtab();
58+
hashtab.hashtabInit();
59+
60+
for (int i = 1; i <= 10; i++) {
61+
hashtab.hashtabAdd("Key" + i, "Value" + i);
62+
}
63+
64+
System.out.println("Поиск Key5: " + hashtab.hashtabLookup("Key5"));
65+
System.out.println("Поиск Key10: " + hashtab.hashtabLookup("Key10"));
66+
67+
hashtab.hashtabDelete("Key5");
68+
System.out.println("Поиск Key5 после удаления: " + hashtab.hashtabLookup("Key5"));
69+
70+
hashtab.hashtabAdd("Key10", "UpdatedValue10");
71+
System.out.println("Обновленное значение Key10: " + hashtab.hashtabLookup("Key10"));
72+
}
73+
}

students/23K0375/23K0375-p28/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-p28</artifactId>
12+
<description>Массивы</description>
13+
</project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package ru.mirea.practice.s23k0375.task1;
2+
3+
import java.util.HashSet;
4+
import java.util.TreeSet;
5+
6+
public abstract class HashToEx {
7+
public static void main(String[] args) {
8+
9+
HashSet<String> hashSet = new HashSet<>();
10+
11+
hashSet.add("geeks");
12+
hashSet.add("practice");
13+
hashSet.add("contribute");
14+
hashSet.add("ide");
15+
16+
System.out.println("HashSet: " + hashSet);
17+
18+
TreeSet<String> treeSet = new TreeSet<>(hashSet);
19+
20+
System.out.println("TreeSet: " + treeSet);
21+
}
22+
}
23+

students/23K0375/23K0375-p29/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-p29</artifactId>
12+
<description>Массивы</description>
13+
</project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package ru.mirea.practice.s23k0375.task1;
2+
3+
public abstract class Main {
4+
public static void main(String[] args) {
5+
int n = 5;
6+
int cnt = 0;
7+
int[][] roadmatr = new int[n][n];
8+
for (int i = 0;i < n;i++) {
9+
roadmatr[0] = new int[]{0,1,0,0,0};
10+
roadmatr[1] = new int[]{1,0,1,1,0};
11+
roadmatr[2] = new int[]{0,1,0,0,0};
12+
roadmatr[3] = new int[]{0,1,0,0,0};
13+
roadmatr[4] = new int[]{0,0,0,0,0};
14+
for (int j = 0;j < n;j++) {
15+
//System.out.println(roadmatr[i][j]);
16+
if (roadmatr[i][j] == 1) {
17+
cnt += 1;
18+
}
19+
}
20+
//System.out.println("");
21+
}
22+
System.out.println("roadnum=" + cnt / 2);
23+
}
24+
}

0 commit comments

Comments
 (0)