Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3. import java.util.List;
  4. import java.util.Scanner;
  5. import java.util.regex.Matcher;
  6. import java.util.regex.Pattern;
  7. import java.util.stream.Collectors;
  8.  
  9. class a04FootballStats {
  10. public static void main(String[] args) {
  11. Scanner Console = new Scanner(System.in);
  12. List<Match> matches = new ArrayList<>();
  13. Pattern params = Pattern.compile("(.*?)\\s+-\\s+(.*?)\\s+result\\s+([0-9]+):([0-9]+)");
  14. while (true){
  15. String input = Console.nextLine();
  16. if(input.equals("Season End"))
  17. break;
  18. Matcher matcher = params.matcher(input);
  19. if(matcher.find()){
  20. System.out.print("");
  21. }
  22. Match match = new Match();
  23. match.setTeam1Name(matcher.group(1));
  24. match.setTeam2Name(matcher.group(2));
  25. match.setTeam1Score(Integer.parseInt(matcher.group(3)));
  26. match.setTeam2Score(Integer.parseInt(matcher.group(4)));
  27. matches.add(match);
  28. }
  29.  
  30. List<String> teams = Arrays.stream(Console.nextLine().split(",\\s+")).collect(Collectors.toList());
  31. for(String s : teams){
  32. matches.stream().filter(e -> e.getTeam1Name().equals(s) || e.getTeam2Name().equals(s)).map(e -> {
  33. if(!e.getTeam1Name().equals(s))
  34. e.switchTeams();
  35. return e;
  36. }).sorted((o1, o2) -> o1.getTeam2Name().compareTo(o2.getTeam2Name())).forEach(e -> {
  37. System.out.println(String.format("%s - %s -> %d:%d", e.getTeam1Name(), e.getTeam2Name(), e.getTeam1Score(), e.getTeam2Score()));
  38. });
  39.  
  40. }
  41. }
  42. }
  43.  
  44. class Match{
  45. private String team1Name;
  46. private String team2Name;
  47. private int team1Score;
  48. private int team2Score;
  49.  
  50. public String getTeam1Name() {
  51. return team1Name;
  52. }
  53.  
  54. public void setTeam1Name(String team1Name) {
  55. this.team1Name = team1Name;
  56. }
  57.  
  58. public String getTeam2Name() {
  59. return team2Name;
  60. }
  61.  
  62. public void setTeam2Name(String team2Name) {
  63. this.team2Name = team2Name;
  64. }
  65.  
  66. public int getTeam1Score() {
  67. return team1Score;
  68. }
  69.  
  70. public void setTeam1Score(int team1Score) {
  71. this.team1Score = team1Score;
  72. }
  73.  
  74. public int getTeam2Score() {
  75. return team2Score;
  76. }
  77.  
  78. public void setTeam2Score(int team2Score) {
  79. this.team2Score = team2Score;
  80. }
  81.  
  82. public void switchTeams(){
  83. int t1Score = this.team1Score;
  84. String t1Name = this.team1Name;
  85. this.team1Name = this.team2Name;
  86. this.team1Score = this.team2Score;
  87. this.team2Name = t1Name;
  88. this.team2Score = t1Score;
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement