public class Solution {
public static List<LineItem> lines = new ArrayList<LineItem>();
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String name1 = reader.readLine();
String name2 = reader.readLine();
reader.close();
BufferedReader fileReader1 = new BufferedReader(new FileReader(name1));
BufferedReader fileReader2 = new BufferedReader(new FileReader(name2));
String line = fileReader1.readLine();
String line2 = fileReader2.readLine();
while(true) {
if(line == null) {
lines.add(new LineItem(Type.ADDED, line2));
break;
}
else if (line2 == null){
lines.add(new LineItem(Type.REMOVED, line));
break;
}
int a = findNumber(line);
int b = findNumber(line2);
if (a == b) {
lines.add(new LineItem(Type.SAME, line));
line = fileReader1.readLine();
line2 = fileReader2.readLine();
}
else if (a > b) {
lines.add(new LineItem(Type.ADDED, line2));
line2 = fileReader2.readLine();
}
else {
lines.add(new LineItem(Type.REMOVED, line));
line = fileReader1.readLine();
}
}
fileReader1.close();
fileReader2.close();
}
public static int findNumber(String line) {
Pattern lastNumber = Pattern.compile("\\d");
Matcher matcher = lastNumber.matcher(line);
int i = 0;
while (matcher.find()){
if(matcher.group() == null){
return i = - 1;
}
i = Integer.parseInt(matcher.group());
}
return i;
}
public static enum Type {
ADDED, //добавлена новая строка
REMOVED, //удалена строка
SAME //без изменений
}
public static class LineItem {
public Type type;
public String line;
public LineItem(Type type, String line) {
this.type = type;
this.line = line;
}
}
}package com.javarush.task.task19.task1916;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/*
Отслеживаем изменения
*/
public class Solution {
public static List<LineItem> lines = new ArrayList<LineItem>();
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String name1 = reader.readLine();
String name2 = reader.readLine();
reader.close();
BufferedReader fileReader1 = new BufferedReader(new FileReader(name1));
BufferedReader fileReader2 = new BufferedReader(new FileReader(name2));
String line = fileReader1.readLine();
String line2 = fileReader2.readLine();
while(true) {
if(line == null) {
lines.add(new LineItem(Type.ADDED, line2));
break;
}
else if (line2 == null){
lines.add(new LineItem(Type.REMOVED, line));
break;
}
int a = findNumber(line);
int b = findNumber(line2);
if (a == b) {
lines.add(new LineItem(Type.SAME, line));
line = fileReader1.readLine();
line2 = fileReader2.readLine();
}
else if (a > b) {
lines.add(new LineItem(Type.ADDED, line2));
line2 = fileReader2.readLine();
}
else {
lines.add(new LineItem(Type.REMOVED, line));
line = fileReader1.readLine();
}
}
fileReader1.close();
fileReader2.close();
}
public static int findNumber(String line) {
Pattern lastNumber = Pattern.compile("\\d");
Matcher matcher = lastNumber.matcher(line);
int i = 0;
while (matcher.find()){
if(matcher.group() == null){
return i = - 1;
}
i = Integer.parseInt(matcher.group());
}
return i;
}
public static enum Type {
ADDED, //добавлена новая строка
REMOVED, //удалена строка
SAME //без изменений
}
public static class LineItem {
public Type type;
public String line;
public LineItem(Type type, String line) {
this.type = type;
this.line = line;
}
}
}