Skip to content
Open
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
18 changes: 11 additions & 7 deletions task01/src/com/example/task01/Task01Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@

public class Task01Main {
public static void main(String[] args) throws IOException {
//здесь вы можете вручную протестировать ваше решение, вызывая реализуемый метод и смотря результат
// например вот так:

// Пример тестирования (раскомментируйте для проверки)
/*
System.out.println(checkSumOfStream(new ByteArrayInputStream(new byte[]{0x33, 0x45, 0x01})));
*/

}

public static int checkSumOfStream(InputStream inputStream) throws IOException {
// your implementation here
return 0;
if (inputStream == null) {
throw new IllegalArgumentException("Input stream cannot be null");
}
int checksum = 0;
int byteRead;
while ((byteRead = inputStream.read()) != -1) {
checksum = Integer.rotateLeft(checksum, 1) ^ byteRead;
}
return checksum;
}
}
}
31 changes: 30 additions & 1 deletion task02/src/com/example/task02/Task02Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,34 @@ public static void main(String[] args) throws IOException {
// - направить стандартный вывод программы в файл output.test
// - запустить программу
// - и сравнить получившийся файл output.test с expected.test

int prevByte = -1;
int currentByte;

while ((currentByte = System.in.read()) != -1) {
if (prevByte == 13) { // если предыдущий байт был '\r'
if (currentByte == 10) { // и текущий байт '\n'
// это последовательность \r\n - заменяем на \n
System.out.write(10);
prevByte = -1; // сбрасываем предыдущий байт
} else {
// одиночный \r, за которым не следует \n
System.out.write(prevByte);
prevByte = currentByte;
}
} else {
if (prevByte != -1) {
System.out.write(prevByte);
}
prevByte = currentByte;
}
}

// После обработки всех байтов выводим оставшийся предыдущий байт
if (prevByte != -1) {
System.out.write(prevByte);
}

System.out.flush(); // обязательно вызываем flush()
}
}
}
19 changes: 15 additions & 4 deletions task03/src/com/example/task03/Task03Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class Task03Main {
public static void main(String[] args) throws IOException {
//здесь вы можете вручную протестировать ваше решение, вызывая реализуемый метод и смотря результат
// здесь вы можете вручную протестировать ваше решение, вызывая реализуемый метод и смотря результат
// например вот так:

/*
Expand All @@ -15,7 +15,18 @@ public static void main(String[] args) throws IOException {
}

public static String readAsString(InputStream inputStream, Charset charset) throws IOException {
// your implementation here
return "";
if (inputStream == null) {
throw new IllegalArgumentException("InputStream cannot be null");
}

byte[] buffer = new byte[1024];
StringBuilder stringBuilder = new StringBuilder();
int bytesRead;

while ((bytesRead = inputStream.read(buffer)) != -1) {
stringBuilder.append(new String(buffer, 0, bytesRead, charset));
}

return stringBuilder.toString();
}
}
}
19 changes: 17 additions & 2 deletions task04/src/com/example/task04/Task04Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.example.task04;

import java.io.IOException;
import java.util.Scanner;
import java.util.Locale;

public class Task04Main {
public static void main(String[] args) throws IOException {
Expand All @@ -9,6 +11,19 @@ public static void main(String[] args) throws IOException {
// - запустить программу
// - проверить, что получилось 351.731900

System.out.println("0.0");
Scanner scanner = new Scanner(System.in);
double sum = 0.0;

while (scanner.hasNext()) {
String token = scanner.next();
try {
double number = Double.parseDouble(token);
sum += number;
} catch (NumberFormatException e) {
// Игнорируем токены, которые не могут быть преобразованы в число
}
}

System.out.printf(Locale.US, "%.6f%n", sum);
}
}
}