/
javapractice
/
JavaPractice
Обзор
Документация
Войти
/
javapractice
/
JavaPractice
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
2
CI/CD
Аналитика
develop
Quiz/src/main/java/quiz/Dublicates2.java
67 строк
2 KB
Zexa91x0
refactoring
25 апр 2021, 11:25
25 апр 2021, 11:25
63c8a42
Код
Авторство
О чём код?
package quiz; import java.io.*; public class Dublicates2 { private static final String FILE_INPUT = "src/input.txt"; private static final String FILE_OUTPUT = "src/output.txt"; private static BufferedReader bufferedReader = null; private static BufferedWriter bufferedWriter = null; private static int MAX_CHAR_ARRAY_SIZE = 15; public static void main(String[] args) throws Exception { init(); run(); close(); } private static void init() throws IOException { bufferedReader = new BufferedReader(new FileReader(FILE_INPUT)); bufferedWriter = new BufferedWriter(new FileWriter(FILE_OUTPUT)); } private static void run() throws IOException { int n = Integer.valueOf(String.valueOf(readLine()).trim()); if (n<1) return; char[] m = writeLine(readLine()); char[] l = m; int i = 1; while (i<n){ m = readLine(); if (!equals(m,l)) l = writeLine(m); ++i; } } private static void close() throws IOException { bufferedWriter.close(); bufferedReader.close(); } private static char[] readLine() throws IOException { char[] res = new char[MAX_CHAR_ARRAY_SIZE]; int count = 0; while (true) { int b = bufferedReader.read(); if (b == '\n' || b == -1) break; if (b == '\r') continue; res[count] = (char) b; count++; } return res; } private static char[] writeLine(char[] IntToFile) throws IOException { bufferedWriter.write(IntToFile); bufferedWriter.newLine(); return IntToFile; } private static boolean equals(char[] chars1, char[] chars2) throws IOException { for (int i = 0; i < MAX_CHAR_ARRAY_SIZE; ++i){ if (chars1[i] != chars2[i]) return false; } return true; } }