Program.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.IO;
  3. namespace D6._1
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. if (args.Length < 1) throw new ArgumentException();
  10. if (File.Exists(args[0]) == false) throw new FileNotFoundException();
  11. var freq = new int[8][];
  12. using (var file = File.OpenText(args[0]))
  13. {
  14. while (true)
  15. {
  16. var line = file.ReadLine();
  17. if (line == null) break;
  18. for (var i = 0; i < 8; i++)
  19. {
  20. if (freq[i] == null) freq[i] = new int[26];
  21. freq[i][line[i] - 'a']++;
  22. }
  23. }
  24. }
  25. var password = new char[8];
  26. for (var i = 0; i < 8; i++)
  27. {
  28. int max = 0, maxi = 0;
  29. for (var ci = 0; ci < 26; ci++)
  30. {
  31. if (freq[i][ci] > max)
  32. {
  33. maxi = ci;
  34. max = freq[i][ci];
  35. }
  36. }
  37. password[i] = (char)(maxi + 'a');
  38. }
  39. Console.WriteLine($"Password is : {string.Join("", password)}");
  40. }
  41. }
  42. }