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

25-32 #695

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions students/23K0375/23K0375-p25/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>23K0375</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0375-p25</artifactId>
<description>Массивы</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package ru.mirea.practice.s23k0375.task1;

import java.util.Scanner;

public final class StrTest {

private StrTest() {
throw new UnsupportedOperationException("Утилитный класс не должен быть создан");
}

public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
System.out.println("Введите строку:");
final String str = sc.nextLine();

System.out.println("Выберите операцию:");
System.out.println("1. Разбить строку на слова");
System.out.println("2. Заменить все пробелы на дефисы");
System.out.println("3. Найти все числа в строке");
System.out.println("4. Удалить все цифры из строки");

int option = sc.nextInt();
sc.nextLine();

switch (option) {
case 1:
String[] words = str.split("\\s+");
System.out.println("Разбитые слова:");
for (String word : words) {
System.out.println(word);
}
break;
case 2:
String rep = str.replaceAll("\\s+", "-");
System.out.println("Строка с замененными пробелами:");
System.out.println(rep);
break;
case 3:
String[] nums = str.split("\\D+");
System.out.println("Найденные числа:");
for (String num : nums) {
if (!num.isEmpty()) {
System.out.println(num);
}
}
break;
case 4:
String noDigits = str.replaceAll("\\d", "");
System.out.println("Строка без цифр:");
System.out.println(noDigits);
break;
default:
System.out.println("Неверный выбор");
break;
}
}
}
}
13 changes: 13 additions & 0 deletions students/23K0375/23K0375-p26/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>23K0375</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0375-p26</artifactId>
<description>Массивы</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package ru.mirea.practice.s23k0375.task1;

import java.util.Stack;

public final class InvArr {

private InvArr() {
throw new UnsupportedOperationException("Utility class");
}

public static void invertArray(int[] arr) {
Stack<Integer> stack = new Stack<>();

for (int num : arr) {
stack.push(num);
}

int i = 0;
for (; i < arr.length; i++) {
arr[i] = stack.pop();
}
}

public static void main(String[] args) {
int[] array = {11, 23, 36, 42, 58, 68, 75, 87, 99};

System.out.println("Исходный массив:");
for (int num : array) {
System.out.print(num + " ");
}
System.out.println();

invertArray(array);

System.out.println("Инвертированный массив:");
for (int num : array) {
System.out.print(num + " ");
}
}
}
13 changes: 13 additions & 0 deletions students/23K0375/23K0375-p27/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>23K0375</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0375-p27</artifactId>
<description>Массивы</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package ru.mirea.practice.s23k0375.task1;

import java.util.LinkedList;

public class Hashtab {
private static final int SIZE = 10;
private LinkedList<Entry>[] table;

static class Entry {
String key;
String value;

Entry(String key, String value) {
this.key = key;
this.value = value;
}
}

public void hashtabInit() {
table = new LinkedList[SIZE];
for (int i = 0; i < SIZE; i++) {
table[i] = new LinkedList<>();
}
}

public int hashtabHash(String key) {
return Math.abs(key.hashCode() % SIZE);
}

public void hashtabAdd(String key, String value) {
int index = hashtabHash(key);
for (Entry entry : table[index]) {
if (entry.key.equals(key)) {
entry.value = value;
return;
}
}
table[index].add(new Entry(key, value));
}

public String hashtabLookup(String key) {
int index = hashtabHash(key);
for (Entry entry : table[index]) {
if (entry.key.equals(key)) {
return entry.value;
}
}
return null;
}

public void hashtabDelete(String key) {
int index = hashtabHash(key);
table[index].removeIf(entry -> entry.key.equals(key));
}

public static void main(String[] args) {
Hashtab hashtab = new Hashtab();
hashtab.hashtabInit();

for (int i = 1; i <= 10; i++) {
hashtab.hashtabAdd("Key" + i, "Value" + i);
}

System.out.println("Поиск Key5: " + hashtab.hashtabLookup("Key5"));
System.out.println("Поиск Key10: " + hashtab.hashtabLookup("Key10"));

hashtab.hashtabDelete("Key5");
System.out.println("Поиск Key5 после удаления: " + hashtab.hashtabLookup("Key5"));

hashtab.hashtabAdd("Key10", "UpdatedValue10");
System.out.println("Обновленное значение Key10: " + hashtab.hashtabLookup("Key10"));
}
}
13 changes: 13 additions & 0 deletions students/23K0375/23K0375-p28/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>23K0375</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0375-p28</artifactId>
<description>Массивы</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ru.mirea.practice.s23k0375.task1;

import java.util.HashSet;
import java.util.TreeSet;

public abstract class HashToEx {
public static void main(String[] args) {

HashSet<String> hashSet = new HashSet<>();

hashSet.add("geeks");
hashSet.add("practice");
hashSet.add("contribute");
hashSet.add("ide");

System.out.println("HashSet: " + hashSet);

TreeSet<String> treeSet = new TreeSet<>(hashSet);

System.out.println("TreeSet: " + treeSet);
}
}

13 changes: 13 additions & 0 deletions students/23K0375/23K0375-p29/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>23K0375</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0375-p29</artifactId>
<description>Массивы</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ru.mirea.practice.s23k0375.task1;

public abstract class Main {
public static void main(String[] args) {
int n = 5;
int cnt = 0;
int[][] roadmatr = new int[n][n];
for (int i = 0;i < n;i++) {
roadmatr[0] = new int[]{0,1,0,0,0};
roadmatr[1] = new int[]{1,0,1,1,0};
roadmatr[2] = new int[]{0,1,0,0,0};
roadmatr[3] = new int[]{0,1,0,0,0};
roadmatr[4] = new int[]{0,0,0,0,0};
for (int j = 0;j < n;j++) {
//System.out.println(roadmatr[i][j]);
if (roadmatr[i][j] == 1) {
cnt += 1;
}
}
//System.out.println("");
}
System.out.println("roadnum=" + cnt / 2);
}
}
13 changes: 13 additions & 0 deletions students/23K0375/23K0375-p30/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>23K0375</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0375-p30</artifactId>
<description>Массивы</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package ru.mirea.practice.s23k0375.task1;

class BinSearchTree {
Node root;


void insert(int value) {
root = insertRec(root, value);
}

Node insertRec(Node root, int value) {
if (root == null) {
root = new Node(value);
return root;
}
if (value < root.value) {
root.left = insertRec(root.left, value);
} else if (value > root.value) {
root.right = insertRec(root.right, value);
}
return root;
}


void inorder() {
inorderRec(root);
}

void inorderRec(Node root) {
if (root != null) {
inorderRec(root.left);
System.out.print(root.value + " ");
inorderRec(root.right);
}
}


void delete(int value) {
root = deleteRec(root, value);
}

Node deleteRec(Node root, int value) {
if (root == null) {
return root;
}
if (value < root.value) {
root.left = deleteRec(root.left, value);
} else if (value > root.value) {
root.right = deleteRec(root.right, value);
} else {

if (root.left == null) {
return root.right;
} else if (root.right == null) {
return root.left;
}

root.value = minValue(root.right);

root.right = deleteRec(root.right, root.value);
}
return root;
}

int minValue(Node root) {
int minValue = root.value;
while (root.left != null) {
minValue = root.left.value;
root = root.left;
}
return minValue;
}
}
Loading