Advertisement
Filkolev

Biggest Table Row

May 27th, 2015
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.89 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4.  
  5. public class BiggestTableRow
  6. {
  7.     public static void Main()
  8.     {
  9.         const string pattern = @"<tr><td>.*?<\/td><td>(.*?)<\/td><td>(.*?)<\/td><td>(.*?)<\/td><\/tr>";
  10.  
  11.         Regex regex = new Regex(pattern);
  12.  
  13.         Console.ReadLine();
  14.         Console.ReadLine();
  15.  
  16.         string row = Console.ReadLine();
  17.  
  18.         double maxSum = double.MinValue;
  19.         bool found = false;
  20.         List<string> elements = new List<string>();
  21.  
  22.         while (row != "</table>")
  23.         {
  24.             var data = regex.Match(row);
  25.             double currentSum = 0;
  26.             List<string> currentElements = new List<string>();
  27.             string firstStore = data.Groups[1].Value;
  28.             string secondStore = data.Groups[2].Value;
  29.             string thirdStore = data.Groups[3].Value;
  30.  
  31.             if (firstStore != "-")
  32.             {
  33.                 found = true;
  34.                 currentSum += double.Parse(firstStore);
  35.                 currentElements.Add(firstStore);
  36.             }
  37.  
  38.             if (secondStore != "-")
  39.             {
  40.                 found = true;
  41.                 currentSum += double.Parse(secondStore);
  42.                 currentElements.Add(secondStore);
  43.             }
  44.  
  45.             if (thirdStore != "-")
  46.             {
  47.                 found = true;
  48.                 currentSum += double.Parse(thirdStore);
  49.                 currentElements.Add(thirdStore);
  50.             }
  51.  
  52.             if (currentSum > maxSum)
  53.             {
  54.                 maxSum = currentSum;
  55.                 elements = currentElements;
  56.             }
  57.  
  58.             row = Console.ReadLine();
  59.         }
  60.  
  61.         if (!found)
  62.         {
  63.             Console.WriteLine("no data");
  64.         }
  65.         else
  66.         {
  67.             Console.WriteLine("{0} = {1}", maxSum, string.Join(" + ", elements));
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement