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
14 changes: 9 additions & 5 deletions task01/src/com/example/task01/Task01Main.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.task01;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

Expand All @@ -8,14 +9,17 @@ 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();
int curByte, checkSum = 0;
while ((curByte = inputStream.read()) != -1) {
checkSum = Integer.rotateLeft(checkSum, 1) ^ curByte;
}
return checkSum;
}
}
}
25 changes: 25 additions & 0 deletions task02/src/com/example/task02/Task02Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,30 @@ public static void main(String[] args) throws IOException {
// - направить стандартный вывод программы в файл output.test
// - запустить программу
// - и сравнить получившийся файл output.test с expected.test
int currentByte;
boolean lastWasCarriageReturn = false;
while((currentByte = System.in.read()) != -1) {
if (currentByte == 13) {
if (lastWasCarriageReturn) System.out.write(13);
lastWasCarriageReturn = true;
}
else if (currentByte == 10) {
if (lastWasCarriageReturn) {
System.out.write(10);
lastWasCarriageReturn = false;
}
else System.out.write(10);
}
else {
if (lastWasCarriageReturn) {
System.out.write(13);
lastWasCarriageReturn= false;
}
System.out.write(currentByte);
}
}

if (lastWasCarriageReturn) System.out.write(13);
System.out.flush();
}
}
14 changes: 10 additions & 4 deletions task03/src/com/example/task03/Task03Main.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.task03;

import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.nio.charset.Charset;

public class Task03Main {
Expand All @@ -15,7 +14,14 @@ 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 || charset == null) throw new IllegalArgumentException();
InputStreamReader reader = new InputStreamReader(inputStream, charset);
BufferedReader bufReader = new BufferedReader(reader);
StringBuilder res = new StringBuilder();
String line;
while ((line = bufReader.readLine()) != null) {
res.append(line);
}
return res.toString();
}
}
11 changes: 10 additions & 1 deletion 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,13 @@ public static void main(String[] args) throws IOException {
// - запустить программу
// - проверить, что получилось 351.731900

System.out.println("0.0");
Scanner scanner = new Scanner(System.in).useLocale(Locale.US);
double sum = 0d;
while (scanner.hasNext()) {
if (scanner.hasNextDouble()) sum += scanner.nextDouble();
else scanner.next();
}
System.out.printf(Locale.US, "%.6f", sum);
scanner.close();
}
}