dlintw
Repos
102
Followers
18
Following
2

Events

hashmaps3 will fail if team 1 duplicate
    fn get_results() -> String {
        let results = "".to_string()
            + "England,France,4,2\n"
            + "France,Italy,3,1\n"
            + "Poland,Spain,2,0\n"
            + "England,Span,3,2\n"      // <- if we add this line, the algorithm will get wrong answer
            + "Germany,England,2,1\n";
        results
    }

So, my solution is

        let team1 = Team {
            name: team_1_name.clone(),
            goals_scored: 0,
            goals_conceded: 0,
        };
        let team2 = Team {
            name: team_2_name.clone(),
            goals_scored: 0,
            goals_conceded: 0,
        };
        let team1 = scores.entry(team_1_name).or_insert(team1);
        team1.goals_scored += team_1_score;
        team1.goals_conceded += team_2_score;
        let team2 = scores.entry(team_2_name).or_insert(team2);
        team2.goals_scored += team_2_score;
        team2.goals_conceded += team_1_score;
    }
Created at 3 days ago
Created at 6 days ago