Skip to content

Commit

Permalink
Done!
Browse files Browse the repository at this point in the history
  • Loading branch information
MaryAlex committed Apr 20, 2016
1 parent b1db91d commit 8dae3a8
Show file tree
Hide file tree
Showing 11 changed files with 317 additions and 206 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.IN
*.OUT
*.OUT
*.txt
330 changes: 219 additions & 111 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Binary file modified out/production/3lab/com/company/Window$1.class
Binary file not shown.
Binary file modified out/production/3lab/com/company/Window$2.class
Binary file not shown.
Binary file modified out/production/3lab/com/company/Window$3.class
Binary file not shown.
Binary file modified out/production/3lab/com/company/Window$4.class
Binary file not shown.
Binary file modified out/production/3lab/com/company/Window$5.class
Binary file not shown.
Binary file modified out/production/3lab/com/company/Window$6.class
Binary file not shown.
Binary file modified out/production/3lab/com/company/Window.class
Binary file not shown.
17 changes: 12 additions & 5 deletions src/com/company/Window.form
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<grid id="27dc6" binding="panel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
<xy x="20" y="20" width="500" height="145"/>
</constraints>
<properties/>
<border type="none"/>
Expand Down Expand Up @@ -52,14 +52,21 @@
</component>
</children>
</grid>
<component id="3c6fe" class="javax.swing.JTextArea" binding="textArea1" default-binding="true">
<scrollpane id="6c0d7">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="150" height="300"/>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="200" height="200"/>
</grid>
</constraints>
<properties/>
</component>
<border type="none"/>
<children>
<component id="80b53" class="javax.swing.JTextArea" binding="textArea1" default-binding="true">
<constraints/>
<properties/>
</component>
</children>
</scrollpane>
</children>
</grid>
</form>
173 changes: 84 additions & 89 deletions src/com/company/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,26 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class Window extends JFrame {
public static final String FILE_END_IN = ".IN";
public static final String FILE_END_OUT = ".OUT";
private List<TestData> allData = new ArrayList<>();
private List<Boolean> answers = new ArrayList<>();
private List<Boolean> toOutput = new ArrayList<>();
private List<TestData> allData = Collections.synchronizedList(new ArrayList<>());
private List<Boolean> answers = Collections.synchronizedList(new ArrayList<>());
private List<Boolean> toOutput = Collections.synchronizedList(new ArrayList<>());
private Thread cheakerIn = new Thread(checkerIn());
private Thread solver = new Thread(solver());
private Thread cheakerOut = new Thread(cheakerOut());
private Integer n;
private List<Integer> n = Collections.synchronizedList(new ArrayList<>());
private JPanel panel;
private JButton startButton;
private JButton stopButton;
Expand All @@ -36,6 +39,8 @@ public class Window extends JFrame {
private JTextArea textArea1;
private String path = "";
private String file = "";
private List<String> files = Collections.synchronizedList(new ArrayList<>());
private File f;

public Window() {
super("Hello");
Expand Down Expand Up @@ -68,42 +73,10 @@ public void actionPerformed(ActionEvent e) {
if (path.equals("")) {
return;
}
File f = new File(path);
for (String fileName : f.list()) {
if (!fileName.endsWith(".IN")) {
continue;
}
file = path + File.separator + fileName.substring(0, fileName.indexOf("."));
cheakerIn.run();
solver.run();
cheakerOut.run();
try {
if (solver.isAlive()) {
solver.wait();
}
} catch (InterruptedException e1) {
e1.printStackTrace();
}
try {
// FileOutputStream out = new FileOutputStream("myAnswer" + file + FILE_END_OUT);
// BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out));
textArea1.append(file + "\n");
for (int i = 0; i < toOutput.size(); i++) {
textArea1.append(i + ". " + toOutput.get(i) + "\n");
// writer.write(toOutput.get(0)? "YES" : "NO");
}
toOutput.clear();
} catch (Exception e1) {
e1.printStackTrace();
}
try {
if (cheakerOut.isAlive()) {
cheakerOut.wait();
}
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
f = new File(path);
cheakerIn.run();
solver.run();
cheakerOut.run();
}
};
}
Expand All @@ -125,10 +98,12 @@ public void run() {
Thread.sleep(1000);
}
}
if (i == n) {
if (i >= n.get(0)) {
n.remove(0);
break;
}
}
System.out.println("Solver done");
} catch (InterruptedException e) {
e.printStackTrace();
}
Expand All @@ -140,29 +115,40 @@ private Runnable cheakerOut() {
return new Runnable() {
@Override
public void run() {
try (FileInputStream in = new FileInputStream(file + FILE_END_OUT);
BufferedReader reader =
new BufferedReader(new InputStreamReader(in))) {
String line = null;
int i = 0;
while (true) {
while (answers.size() != 0) {
while (true) {
while (files.size() != 0) {
textArea1.append(files.get(0) + "\n");
try (FileInputStream in = new FileInputStream(files.get(0) + FILE_END_OUT);
BufferedReader reader =
new BufferedReader(new InputStreamReader(in))) {
File fileOutput = new File(files.get(0) + "programs.txt");
PrintWriter writer = new PrintWriter(fileOutput, "UTF-8");
String line = "";
int i = 0;
while ((line = reader.readLine()) != null) {
String answer = answers.get(0)? "YES" : "NO";
writer.print(i + ". " + answer + "\n");
writer.flush();
textArea1.append(i + ". " + answer + "\n");
if (!answer.equals(line)) {
textArea1.append("Wrong answer in " + i + " test!");
textArea1.append("Wrong answer in " + i + " test! It's wrong answer upper!\n");
writer.print("Wrong answer in " + i + " test! It's wrong answer upper!\n");
writer.flush();
}
answers.remove(0);
i++;
System.out.println(line + " line");
}
}
if (i == n) {
break;
writer.close();
files.remove(0);
} catch (IOException x) {
System.err.println(x);
}
}
} catch (IOException x) {
System.err.println(x);
if (!cheakerIn.isAlive()) {
break;
}
System.out.println("checkerOut done!");
}
}
};
Expand All @@ -172,47 +158,56 @@ private Runnable checkerIn() {
return new Runnable() {
@Override
public void run() {
try (FileInputStream in = new FileInputStream(file + FILE_END_IN);
BufferedReader reader =
new BufferedReader(new InputStreamReader(in))) {
String line = null;
if ((line = reader.readLine()) != null) {
System.out.println(line + " line");
}
if (line == null || line.contains(" ")) {
System.out.println("Incorrect data");
n = 0;
return;
}
n = Integer.valueOf(line);
if (n < 1 || n > 5) {
System.out.println("Incorrect data");
n = 0;
return;
outerloop:
for (String fileName : f.list()) {
if (!fileName.endsWith(".IN")) {
continue;
}
System.out.println(n + " n");
for (int i = 0; i < n; i++) {
String test = reader.readLine();
List<String> data = new ArrayList<>(Arrays.asList(test.split(" ")));
data.removeIf(s -> s.equals(""));
if (data.size() > 12) {
file = path + File.separator + fileName.substring(0, fileName.indexOf("."));
try (FileInputStream in = new FileInputStream(file + FILE_END_IN);
BufferedReader reader =
new BufferedReader(new InputStreamReader(in))) {
String line = null;
if ((line = reader.readLine()) != null) {
System.out.println(line + " line");
}
if (line == null || line.contains(" ")) {
System.out.println("Incorrect data");
n = 0;
return;
n.add(0);
continue;
}
List<BoxPanel> panels = new ArrayList<>();
for (int j = 0; j < 12; j += 2) {
if (Integer.valueOf(data.get(j)) > 10000 || Integer.valueOf(data.get(j + 1)) > 10000) {
n = 0;
return;
Integer nLocal = Integer.valueOf(line);
if (nLocal < 1 || nLocal > 5) {
System.out.println("Incorrect data");
nLocal = 0;
continue;
}
System.out.println(nLocal + " n");
for (int i = 0; i < nLocal; i++) {
String test = reader.readLine();
List<String> data = new ArrayList<>(Arrays.asList(test.split(" ")));
data.removeIf(s -> s.equals(""));
if (data.size() > 12) {
System.out.println("Incorrect data");
nLocal = 0;
continue outerloop;
}
List<BoxPanel> panels = new ArrayList<>();
for (int j = 0; j < 12; j += 2) {
if (Integer.valueOf(data.get(j)) > 10000 || Integer.valueOf(data.get(j + 1)) > 10000) {
nLocal = 0;
continue outerloop;
}
panels.add(new BoxPanel(Integer.valueOf(data.get(j)), Integer.valueOf(data.get(j + 1))));
}
panels.add(new BoxPanel(Integer.valueOf(data.get(j)), Integer.valueOf(data.get(j+1))));
allData.add(new TestData(panels));
System.out.println(i + " i in reading");
}
allData.add(new TestData(panels));
System.out.println(i + " i in reading");
files.add(file);
n.add(nLocal);
} catch (IOException x) {
System.err.println(x);
}
} catch (IOException x) {
System.err.println(x);
}
}
};
Expand Down

0 comments on commit 8dae3a8

Please sign in to comment.