Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.97 KB | None | 0 0
  1.         public static string Cut(string item, string from = null, string to = null)
  2.         {
  3.             int From = from == null ? 0 : item.IndexOf(from) + 1;
  4.             int To = to == null ? item.Length : item.IndexOf(to);
  5.             return item.Substring(From, To - From);
  6.         }
  7.  
  8.         public static string DashToInt(string dash)
  9.         {
  10.             if (dash == "-")
  11.                 return "0";
  12.             else
  13.                 return dash;
  14.         }
  15.  
  16.         public static void FridayEveningTest()
  17.         {
  18.             var results = new[]
  19.             {
  20.         "6:0 FC Bayern Muenchen - Werder Bremen",
  21.         "-:- Eintracht Frankfurt - Schalke 04",
  22.         "-:- FC Augsburg - VfL Wolfsburg",
  23.         "-:- Hamburger SV - FC Ingolstadt",
  24.         "-:- 1. FC Koeln - SV Darmstadt",
  25.         "-:- Borussia Dortmund - FSV Mainz 05",
  26.         "-:- Borussia Moenchengladbach - Bayer Leverkusen",
  27.         "-:- Hertha BSC Berlin - SC Freiburg",
  28.         "-:- TSG 1899 Hoffenheim - RasenBall Leipzig"
  29.             };
  30.  
  31.             List<Club> clubs = new List<Club>(results.Length);
  32.  
  33.             foreach (var item in results)
  34.             {
  35.                 string goalsPart = Cut(item, null, " ");
  36.                 string restPart = Cut(item, " ", null);
  37.  
  38.                 Club WonTeam = new Club() { Name = Cut(restPart, null, " -") };
  39.                 Club LoseTeam = new Club() { Name = Cut(restPart, "-", null).Trim() };
  40.  
  41.                 WonTeam.GoalsShot = Convert.ToInt32(DashToInt(Cut(goalsPart, null, ":")));
  42.                 WonTeam.GoalsGotten = Convert.ToInt32(DashToInt(Cut(goalsPart, ":", null)));
  43.                 LoseTeam.GoalsGotten = Convert.ToInt32(DashToInt(Cut(goalsPart, null, ":")));
  44.                 LoseTeam.GoalsShot = Convert.ToInt32(DashToInt(Cut(goalsPart, ":", null)));
  45.  
  46.                 if (!(Cut(goalsPart, null, ":") == "-"))
  47.                 {
  48.                     WonTeam.PlayedMatches += 1;
  49.                     LoseTeam.PlayedMatches += 1;
  50.  
  51.                     if (WonTeam.GoalsShot == LoseTeam.GoalsShot)
  52.                     { WonTeam.Points += 1; WonTeam.Ties += 1; LoseTeam.Points += 1; LoseTeam.Ties += 1; }
  53.                     else
  54.                     { WonTeam.Wins += 1; WonTeam.Points += 3; LoseTeam.Loses += 1; }
  55.                 }
  56.  
  57.                 clubs.Add(WonTeam);
  58.                 clubs.Add(LoseTeam);
  59.             }
  60.  
  61.             clubs = clubs.OrderBy(a => a.Name).ToList();
  62.             clubs = clubs.OrderBy(a => a.GoalsShot).ToList();
  63.             clubs = clubs.OrderByDescending(a => a.Points).ToList();
  64.  
  65.             var tempClub = new Club();
  66.  
  67.             for (int i = 0; i < clubs.Count; i++)
  68.             {
  69.                 clubs[i].Place = i + 1;
  70.                 if (clubs[i].Points == tempClub.Points || clubs[i].PlayedMatches == 0)
  71.                     clubs[i].Place = tempClub.Place;
  72.                 else
  73.                     clubs[i].Place = clubs.Count;
  74.  
  75.                 tempClub = clubs[i];
  76.             }
  77.  
  78.         }
  79.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement