package com.javarush.task.task17.task1721;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
/*
Транзакционность
*/
public class Solution {
public static List<String> allLines = new ArrayList<String>();
public static List<String> forRemoveLines = new ArrayList<String>();
public static void main(String[] args) {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
try{
String fName1 = reader.readLine();
String fName2 = reader.readLine();
reader.close();
allLines = reader(fName1);
forRemoveLines = reader(fName2);
Solution solution = new Solution();
solution.joinData(allLines, forRemoveLines);
}catch (IOException e){
e.printStackTrace();
}}
public static List<String> reader(String fName) throws IOException {
List<String> list = new ArrayList<>();
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(fName)));
String s;
while ((s=reader.readLine())!=null){
list.add(s);
}
reader.close();
return list;
}
public void joinData (List list1,List list2) throws CorruptedDataException {
int count=0;
for (int i=0;i<list2.size();i++){
for (int j=0;j<list1.size();j++){
if (list2.get(i).equals(list1.get(j))){
count++;
}
}
}
if (count>=list2.size()){
for (int i=0;i<list2.size();i++)
for (int j=0;j<list1.size();j++)
if (list2.get(i).equals(list1.get(j))){
list1.remove(j);
j--;
}
}
else {
allLines.clear();
throw new CorruptedDataException();
}
}
}
package com.javarush.task.task17.task1721;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
/*
Транзакционность
*/
public class Solution {
public static List<String> allLines = new ArrayList<String>();
public static List<String> forRemoveLines = new ArrayList<String>();
public static void main(String[] args) {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
try{
String fName1 = reader.readLine();
String fName2 = reader.readLine();
reader.close();
allLines = reader(fName1);
forRemoveLines = reader(fName2);
Solution solution = new Solution();
solution.joinData(allLines, forRemoveLines);
}catch (IOException e){
e.printStackTrace();
}}
public static List<String> reader(String fName) throws IOException {
List<String> list = new ArrayList<>();
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(fName)));
String s;
while ((s=reader.readLine())!=null){
list.add(s);
}
reader.close();
return list;
}
public void joinData (List list1,List list2) throws CorruptedDataException {
int count=0;
for (int i=0;i<list2.size();i++){
for (int j=0;j<list1.size();j++){
if (list2.get(i).equals(list1.get(j))){
count++;
}
}
}
if (count>=list2.size()){
for (int i=0;i<list2.size();i++)
for (int j=0;j<list1.size();j++)
if (list2.get(i).equals(list1.get(j))){
list1.remove(j);
j--;
}
}
else {
allLines.clear();
throw new CorruptedDataException();
}
}
}