Advertisement
Guest User

Largest 3 Rectangles

a guest
Oct 3rd, 2015
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7. class UserLogs
  8. {
  9. static void Main()
  10. {
  11. string input = Console.ReadLine();
  12. string pattern = @"]\s+";
  13. string[] substrings = Regex.Split(input, pattern);
  14.  
  15. List<int> nums = new List<int>();
  16. for (int i = 0; i < substrings.Length; i++)
  17. {
  18. string[] numbers = Regex.Split(substrings[i], @"\D+");
  19. for (int i2 = 0; i2 < numbers.Length; i2++)
  20. {
  21. if (!string.IsNullOrEmpty(numbers[i2]))
  22. {
  23. nums.Add(int.Parse(numbers[i2]));
  24. }
  25. }
  26. }
  27. List<int> res = new List<int>();
  28. for (int i3 = 0; i3 < nums.Count - 1; i3 += 2)
  29. {
  30. res.Add(nums[i3] * nums[i3 + 1]);
  31. }
  32. List<int> combine3 = new List<int>();
  33. for (int i4 = 0; i4 < res.Count - 2; i4++)
  34. {
  35. combine3.Add(res[i4] + res[i4 + 1] + res[i4 + 2]);
  36. }
  37.  
  38. combine3.Sort((a, b) => -1 * a.CompareTo(b));
  39.  
  40. Console.WriteLine(combine3[0]);
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement