Program.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. namespace D3._2
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. if (args.Length < 1) return;
  12. if (File.Exists(args[0]) == false) return;
  13. var file = File.OpenText(args[0]);
  14. var fabric = new HashSet<string>[1000, 1000];
  15. do
  16. {
  17. var line = file.ReadLine();
  18. if (line == null) break;
  19. var n = line.Split("@")[0];
  20. var l = line.Split("@")[1];
  21. var xy = l.Split(":")[0];
  22. var wh = l.Split(":")[1];
  23. var x = int.Parse(xy.Split(",")[0]);
  24. var y = int.Parse(xy.Split(",")[1]);
  25. var w = int.Parse(wh.Split("x")[0]);
  26. var h = int.Parse(wh.Split("x")[1]);
  27. for (int i = x; i < x + w; i++)
  28. {
  29. for (int j = y; j < y + h; j++)
  30. {
  31. if (fabric[i, j] == null) fabric[i, j] = new HashSet<string>();
  32. fabric[i, j].Add(n);
  33. }
  34. }
  35. } while (true);
  36. Dictionary<string, bool> all = new Dictionary<string, bool>();
  37. for (int x = 0; x < 1000; x++)
  38. {
  39. for (int y = 0; y < 1000; y++)
  40. {
  41. if (fabric[x, y] == null) continue;
  42. var fl = fabric[x, y];
  43. if (fl.Count == 1 && all.ContainsKey(fl.FirstOrDefault()) == false)
  44. {
  45. all.Add(fl.FirstOrDefault(), true);
  46. }
  47. if (fl.Count == 1) continue;
  48. foreach (var f in fl)
  49. {
  50. if (all.ContainsKey(f) == false) all.Add(f, false);
  51. else all[f] = false;
  52. }
  53. }
  54. }
  55. Console.WriteLine(all.FirstOrDefault(a => a.Value == true));
  56. }
  57. }
  58. }