Program.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. namespace D2._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 list = new List<string>();
  15. string code = null;
  16. do
  17. {
  18. var line = file.ReadLine();
  19. if (line == null) break;
  20. foreach (var l in list)
  21. {
  22. int diffCars = 0;
  23. string c = string.Empty;
  24. for (int i = 0; i < l.Length; i++)
  25. {
  26. if (l[i] != line[i]) diffCars++;
  27. else c += l[i];
  28. if (diffCars >= 2) break;
  29. }
  30. if (diffCars == 1)
  31. {
  32. code = c;
  33. break;
  34. };
  35. }
  36. list.Add(line);
  37. } while (code == null);
  38. Console.WriteLine(code);
  39. }
  40. }
  41. }