mirror of
https://github.com/Xevion/contest.git
synced 2025-12-15 16:11:21 -06:00
feb 2015 problem 1 / 3 / 4
This commit is contained in:
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