Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import java.util.stream.Collectors;
- class a04FootballStats {
- public static void main(String[] args) {
- Scanner Console = new Scanner(System.in);
- List<Match> matches = new ArrayList<>();
- Pattern params = Pattern.compile("(.*?)\\s+-\\s+(.*?)\\s+result\\s+([0-9]+):([0-9]+)");
- while (true){
- String input = Console.nextLine();
- if(input.equals("Season End"))
- break;
- Matcher matcher = params.matcher(input);
- if(matcher.find()){
- System.out.print("");
- }
- Match match = new Match();
- match.setTeam1Name(matcher.group(1));
- match.setTeam2Name(matcher.group(2));
- match.setTeam1Score(Integer.parseInt(matcher.group(3)));
- match.setTeam2Score(Integer.parseInt(matcher.group(4)));
- matches.add(match);
- }
- List<String> teams = Arrays.stream(Console.nextLine().split(",\\s+")).collect(Collectors.toList());
- for(String s : teams){
- matches.stream().filter(e -> e.getTeam1Name().equals(s) || e.getTeam2Name().equals(s)).map(e -> {
- if(!e.getTeam1Name().equals(s))
- e.switchTeams();
- return e;
- }).sorted((o1, o2) -> o1.getTeam2Name().compareTo(o2.getTeam2Name())).forEach(e -> {
- System.out.println(String.format("%s - %s -> %d:%d", e.getTeam1Name(), e.getTeam2Name(), e.getTeam1Score(), e.getTeam2Score()));
- });
- }
- }
- }
- class Match{
- private String team1Name;
- private String team2Name;
- private int team1Score;
- private int team2Score;
- public String getTeam1Name() {
- return team1Name;
- }
- public void setTeam1Name(String team1Name) {
- this.team1Name = team1Name;
- }
- public String getTeam2Name() {
- return team2Name;
- }
- public void setTeam2Name(String team2Name) {
- this.team2Name = team2Name;
- }
- public int getTeam1Score() {
- return team1Score;
- }
- public void setTeam1Score(int team1Score) {
- this.team1Score = team1Score;
- }
- public int getTeam2Score() {
- return team2Score;
- }
- public void setTeam2Score(int team2Score) {
- this.team2Score = team2Score;
- }
- public void switchTeams(){
- int t1Score = this.team1Score;
- String t1Name = this.team1Name;
- this.team1Name = this.team2Name;
- this.team1Score = this.team2Score;
- this.team2Name = t1Name;
- this.team2Score = t1Score;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement