Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static string Cut(string item, string from = null, string to = null)
- {
- int From = from == null ? 0 : item.IndexOf(from) + 1;
- int To = to == null ? item.Length : item.IndexOf(to);
- return item.Substring(From, To - From);
- }
- public static string DashToInt(string dash)
- {
- if (dash == "-")
- return "0";
- else
- return dash;
- }
- public static void FridayEveningTest()
- {
- var results = new[]
- {
- "6:0 FC Bayern Muenchen - Werder Bremen",
- "-:- Eintracht Frankfurt - Schalke 04",
- "-:- FC Augsburg - VfL Wolfsburg",
- "-:- Hamburger SV - FC Ingolstadt",
- "-:- 1. FC Koeln - SV Darmstadt",
- "-:- Borussia Dortmund - FSV Mainz 05",
- "-:- Borussia Moenchengladbach - Bayer Leverkusen",
- "-:- Hertha BSC Berlin - SC Freiburg",
- "-:- TSG 1899 Hoffenheim - RasenBall Leipzig"
- };
- List<Club> clubs = new List<Club>(results.Length);
- foreach (var item in results)
- {
- string goalsPart = Cut(item, null, " ");
- string restPart = Cut(item, " ", null);
- Club WonTeam = new Club() { Name = Cut(restPart, null, " -") };
- Club LoseTeam = new Club() { Name = Cut(restPart, "-", null).Trim() };
- WonTeam.GoalsShot = Convert.ToInt32(DashToInt(Cut(goalsPart, null, ":")));
- WonTeam.GoalsGotten = Convert.ToInt32(DashToInt(Cut(goalsPart, ":", null)));
- LoseTeam.GoalsGotten = Convert.ToInt32(DashToInt(Cut(goalsPart, null, ":")));
- LoseTeam.GoalsShot = Convert.ToInt32(DashToInt(Cut(goalsPart, ":", null)));
- if (!(Cut(goalsPart, null, ":") == "-"))
- {
- WonTeam.PlayedMatches += 1;
- LoseTeam.PlayedMatches += 1;
- if (WonTeam.GoalsShot == LoseTeam.GoalsShot)
- { WonTeam.Points += 1; WonTeam.Ties += 1; LoseTeam.Points += 1; LoseTeam.Ties += 1; }
- else
- { WonTeam.Wins += 1; WonTeam.Points += 3; LoseTeam.Loses += 1; }
- }
- clubs.Add(WonTeam);
- clubs.Add(LoseTeam);
- }
- clubs = clubs.OrderBy(a => a.Name).ToList();
- clubs = clubs.OrderBy(a => a.GoalsShot).ToList();
- clubs = clubs.OrderByDescending(a => a.Points).ToList();
- var tempClub = new Club();
- for (int i = 0; i < clubs.Count; i++)
- {
- clubs[i].Place = i + 1;
- if (clubs[i].Points == tempClub.Points || clubs[i].PlayedMatches == 0)
- clubs[i].Place = tempClub.Place;
- else
- clubs[i].Place = clubs.Count;
- tempClub = clubs[i];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement