mirror of
https://github.com/Xevion/contest.git
synced 2025-12-15 14:11:23 -06:00
feb 2015 problem 1 / 3 / 4
This commit is contained in:
11
uil/aplus-february-2015/1/Automaton.MD
Normal file
11
uil/aplus-february-2015/1/Automaton.MD
Normal file
@@ -0,0 +1,11 @@
|
||||
# Automaton
|
||||
|
||||
Run my solution on **[repl.it](https://repl.it/@Xevion/A-Computer-Science-February-2015-Automaton)!**
|
||||
|
||||
A rather simple problem, despite the overwhelming complicated background information to understand what it's talking about in the first paragraph.
|
||||
|
||||
I recommend skipping the first paragraph, and simply looking at the second one very carefully. In short, the entire problem is basically Regex.
|
||||
|
||||
All you have to do is manipulate the input data, create a function for matching, loop until you find a input that works, and you're done.
|
||||
|
||||
There was one big problem though I encountered, one that would have been a failed submission in the end.
|
||||
39
uil/aplus-february-2015/1/Automaton.java
Normal file
39
uil/aplus-february-2015/1/Automaton.java
Normal file
@@ -0,0 +1,39 @@
|
||||
import static java.lang.System.out;
|
||||
import java.util.Scanner;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
class Automaton {
|
||||
private String match;
|
||||
private String input;
|
||||
|
||||
public Automaton(String match, String input) {
|
||||
match = String.format("^%s$", match);
|
||||
this.match = match.replace('U', '|');
|
||||
this.input = input;
|
||||
}
|
||||
|
||||
public String search() {
|
||||
String cInput = this.input;
|
||||
while(cInput.length() > 0) {
|
||||
// out.println(String.format("%s %s", match, cInput));
|
||||
if(cInput.matches(this.match))
|
||||
if(cInput.length() == this.input.length())
|
||||
return "YES";
|
||||
else
|
||||
return String.format("NO %s", cInput.length());
|
||||
cInput = cInput.substring(0, cInput.length() - 1);
|
||||
}
|
||||
return "NO 0";
|
||||
}
|
||||
}
|
||||
|
||||
class Main {
|
||||
public static void main(String[] args) throws IOException {
|
||||
Scanner s = new Scanner(new File("automaton.dat"));
|
||||
while(s.hasNextLine()) {
|
||||
Automaton fsa = new Automaton(s.next(), s.next());
|
||||
out.println(fsa.search());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user