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

Commit a407b0b

Browse files
authored
Merge pull request #598 from Arkadiy-Git/labfinal
Merge remote-tracking branch 'origin/lab1120' into lab31-32
2 parents e788e90 + 90baa18 commit a407b0b

File tree

5 files changed

+138
-6
lines changed

5 files changed

+138
-6
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package ru.mirea.practice.s0000001.task1;
2+
3+
import java.io.BufferedReader;
4+
import java.io.File;
5+
import java.io.FileReader;
6+
import java.io.IOException;
7+
import java.util.ArrayList;
8+
import java.util.List;
9+
10+
public final class FileHandler {
11+
12+
private FileHandler() {
13+
}
14+
15+
public static List<ProcessorRecord> readFile(String filePath) {
16+
List<ProcessorRecord> records = new ArrayList<>();
17+
BufferedReader reader = null;
18+
19+
try {
20+
reader = new BufferedReader(new FileReader(new File(filePath)));
21+
String line;
22+
while ((line = reader.readLine()) != null) {
23+
String[] parts = line.split(",");
24+
if (parts.length == 7) {
25+
int key = Integer.parseInt(parts[0].trim());
26+
String name = parts[1].trim();
27+
double clockFrequency = Double.parseDouble(parts[2].trim());
28+
int cacheSize = Integer.parseInt(parts[3].trim());
29+
double busFrequency = Double.parseDouble(parts[4].trim());
30+
int specint = Integer.parseInt(parts[5].trim());
31+
int specfp = Integer.parseInt(parts[6].trim());
32+
33+
ProcessorRecord record = new ProcessorRecord(
34+
key, name, clockFrequency, cacheSize, busFrequency, specint, specfp);
35+
records.add(record);
36+
}
37+
}
38+
} catch (IOException e) {
39+
System.out.println("Error reading file: " + e.getMessage());
40+
} finally {
41+
try {
42+
if (reader != null) {
43+
reader.close();
44+
}
45+
} catch (IOException e) {
46+
System.out.println("Error closing reader: " + e.getMessage());
47+
}
48+
}
49+
50+
return records;
51+
}
52+
}

students/23K1226/23K1226-p31/src/main/java/ru.mirea.practice.s0000001.task1/Main.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
import java.util.Locale;
44
import java.util.Scanner;
55

6-
public class Main {
6+
public final class Main {
7+
78
private static Scanner scanner = new Scanner(System.in);
8-
private TwoThreeTree tree = new TwoThreeTree();
9+
private static TwoThreeTree tree = new TwoThreeTree();
10+
11+
private Main() {
12+
}
913

10-
public void run() {
14+
public static void run() {
1115
while (true) {
1216
System.out.println("Enter command (L, D, A, S, E):");
1317
String command = scanner.nextLine().trim().toUpperCase(Locale.ROOT);
@@ -51,7 +55,6 @@ public void run() {
5155

5256
case "S":
5357
System.out.println("Saving to file...");
54-
// Здесь можно добавить код для сохранения данных в файл
5558
break;
5659

5760
case "E":
@@ -67,7 +70,6 @@ public void run() {
6770
}
6871

6972
public static void main(String[] args) {
70-
Main app = new Main();
71-
app.run();
73+
run();
7274
}
7375
}
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-p32</artifactId>
12+
<description> </description>
13+
</project>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package ru.mirea.practice.s0000001.task1;
2+
3+
public final class JohnsonTrotter {
4+
private JohnsonTrotter() {
5+
}
6+
7+
private static void printPermutation(int[] arr) {
8+
for (int num : arr) {
9+
System.out.print(num + " ");
10+
}
11+
System.out.println();
12+
}
13+
14+
public static void generatePermutations(int n) {
15+
int[] arr = new int[n];
16+
int[] directions = new int[n];
17+
18+
for (int i = 0; i < n; i++) {
19+
arr[i] = i + 1;
20+
directions[i] = -1;
21+
}
22+
23+
printPermutation(arr);
24+
25+
boolean finished = false;
26+
while (!finished) {
27+
int largestMobile = -1;
28+
int largestMobileIndex = -1;
29+
30+
for (int i = 0; i < n; i++) {
31+
int curr = arr[i];
32+
int dir = directions[i];
33+
int nextIndex = i + dir;
34+
35+
if (nextIndex >= 0 && nextIndex < n && arr[nextIndex] < curr) {
36+
if (curr > largestMobile) {
37+
largestMobile = curr;
38+
largestMobileIndex = i;
39+
}
40+
}
41+
}
42+
43+
if (largestMobile == -1) {
44+
finished = true;
45+
} else {
46+
int moveIndex = largestMobileIndex;
47+
int moveValue = arr[moveIndex];
48+
int moveDirection = directions[moveIndex];
49+
50+
arr[moveIndex] = arr[moveIndex + moveDirection];
51+
arr[moveIndex + moveDirection] = moveValue;
52+
53+
directions[moveIndex] = -directions[moveIndex];
54+
55+
printPermutation(arr);
56+
}
57+
}
58+
}
59+
60+
public static void main(String[] args) {
61+
int n = 3;
62+
generatePermutations(n);
63+
}
64+
}

students/23K1226/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@
4646
<module>23K1226-p30</module>
4747
<module>23K1226-p30.2</module>
4848
<module>23K1226-p31</module>
49+
<module>23K1226-p32</module>
4950
</modules>
5051
</project>

0 commit comments

Comments
 (0)