Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- public class BiggestTableRow
- {
- public static void Main()
- {
- const string pattern = @"<tr><td>.*?<\/td><td>(.*?)<\/td><td>(.*?)<\/td><td>(.*?)<\/td><\/tr>";
- Regex regex = new Regex(pattern);
- Console.ReadLine();
- Console.ReadLine();
- string row = Console.ReadLine();
- double maxSum = double.MinValue;
- bool found = false;
- List<string> elements = new List<string>();
- while (row != "</table>")
- {
- var data = regex.Match(row);
- double currentSum = 0;
- List<string> currentElements = new List<string>();
- string firstStore = data.Groups[1].Value;
- string secondStore = data.Groups[2].Value;
- string thirdStore = data.Groups[3].Value;
- if (firstStore != "-")
- {
- found = true;
- currentSum += double.Parse(firstStore);
- currentElements.Add(firstStore);
- }
- if (secondStore != "-")
- {
- found = true;
- currentSum += double.Parse(secondStore);
- currentElements.Add(secondStore);
- }
- if (thirdStore != "-")
- {
- found = true;
- currentSum += double.Parse(thirdStore);
- currentElements.Add(thirdStore);
- }
- if (currentSum > maxSum)
- {
- maxSum = currentSum;
- elements = currentElements;
- }
- row = Console.ReadLine();
- }
- if (!found)
- {
- Console.WriteLine("no data");
- }
- else
- {
- Console.WriteLine("{0} = {1}", maxSum, string.Join(" + ", elements));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement