Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- namespace Code_Katas
- {
- public class Football
- {
- public static string FindTeamWithSmallestDifference3(string fileName)
- {
- var data = File.OpenText(fileName).ReadToEnd();
- int currentLeastDifference = int.MaxValue;
- string currentLeastDifferenceTeam = String.Empty;
- var onlyData = data.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries)
- .Where(r => char.IsNumber(r.TrimStart()[0]));
- foreach (var item in onlyData)
- {
- var dataOfTeam = item.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- var difference = Math.Abs(int.Parse(dataOfTeam[6]) - int.Parse(dataOfTeam[8]));
- if (difference < currentLeastDifference)
- {
- currentLeastDifference = difference;
- currentLeastDifferenceTeam = dataOfTeam[1];
- }
- }
- return currentLeastDifferenceTeam;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement