Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package october2015;
- import java.util.*;
- import java.util.regex.*;
- public class DragonSharp {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int lines = Integer.parseInt(scan.nextLine());
- String[] input = new String[lines];
- Pattern patternif = Pattern.compile("[a-z]+ \\(([0-9]+)(\\=\\=|\\>|\\<)+([0-9]+)\\) (.*out) (\\\"(.+)\\\"\\;)");
- Pattern patternelse = Pattern.compile("else (.*out) (\\\"(.+)\\\"\\;)");
- int validCounter = 0;
- int trueCount = 0;
- for (int i = 0; i < lines; i++) {
- input[i] = scan.nextLine();
- Matcher matchIf = patternif.matcher(input[i]);
- Matcher matchElse = patternelse.matcher(input[i]);
- if (matchIf.find()) {
- validCounter++;
- } else if (matchElse.find()) {
- validCounter++;
- } else { break;}
- }
- if (validCounter == lines) {
- for (int i = 0; i < lines; i++) {
- Matcher matchIf = patternif.matcher(input[i]);
- Matcher matchElse = patternelse.matcher(input[i]);
- if (matchIf.find()) {
- boolean isTrue = false;
- int num1 = Integer.parseInt(matchIf.group(1));
- int num2 = Integer.parseInt(matchIf.group(3));
- String condition = matchIf.group(2);
- if (condition.equals("==") && num1 == num2) {
- isTrue = true;
- } else if (condition.equals(">") && num1 > num2) {
- isTrue = true;
- } else if (condition.equals("<") && num1 < num2) {
- isTrue = true;
- }
- if (isTrue) {
- String[] loops = matchIf.group(4).split(" ");
- if (loops.length == 1) {
- System.out.println(matchIf.group(6));
- } else {
- for (int j = 0; j < Integer.parseInt(loops[1]); j++) {
- System.out.println(matchIf.group(6));
- }
- }
- trueCount++;
- }
- } else if (matchElse.find() && trueCount == i - 1) {
- String[] loops = matchElse.group(1).split(" ");
- if (loops.length == 1) {
- System.out.println(matchElse.group(3));
- } else {
- for (int j = 0; j < Integer.parseInt(loops[1]); j++) {
- System.out.println(matchElse.group(3));
- }
- }
- trueCount++;
- } else {
- trueCount++;
- }
- }
- } else {
- System.out.println("Compile time error @ line " + (validCounter + 1));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement