Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. import java.nio.file.Files;
  2. import java.nio.file.Paths;
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.regex.Matcher;
  6. import java.util.regex.Pattern;
  7.  
  8. public class Main {
  9.  
  10. private static List<String> questions = new ArrayList<>();
  11. private static List<String> options = new ArrayList<>();
  12. private static List<String> answers = new ArrayList<>();
  13.  
  14. public static void main(String[] args) throws Exception {
  15. String lines = readFileAsString("questions.txt");
  16.  
  17. Pattern pattern = Pattern.compile("[ \\t]*\\d+\\)[^\\n]+");
  18. Matcher m = pattern.matcher(lines);
  19. while (m.find()) {
  20. questions.add(m.group());
  21. }
  22.  
  23. m.usePattern(Pattern.compile("(?:[ \\t]*[a-zA-Z]\\)[^\\n]+\\n)+"));
  24. m.reset();
  25. while (m.find()) {
  26. options.add(m.group());
  27. }
  28.  
  29. m.usePattern(Pattern.compile("Answer:[^\\n]*"));
  30. m.reset();
  31. while (m.find()) {
  32. answers.add(m.group());
  33. }
  34.  
  35.  
  36. questions.forEach(System.out::println);
  37. options.forEach(System.out::println);
  38. answers.forEach(System.out::println);
  39. }
  40.  
  41. private static String readFileAsString(String fileName) throws Exception {
  42. String data = "";
  43. data = new String(Files.readAllBytes(Paths.get(fileName)));
  44. return data;
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement