Advertisement
Guest User

Untitled

a guest
May 28th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. using System;
  2.  
  3. using System.Collections.Generic;
  4.  
  5. using System.Linq;
  6.  
  7. using System.Text;
  8.  
  9. using System.Threading.Tasks;
  10.  
  11. using System.IO;
  12.  
  13. namespace ConsoleApplication33
  14.  
  15. {
  16.  
  17. class Program
  18.  
  19. {
  20.  
  21. static void Main(string[] args)
  22.  
  23. {
  24.  
  25. double f = 0;
  26.  
  27. var path = @"C:/Users/davla/Desktop/4.tif";
  28.  
  29. byte[] b = File.ReadAllBytes(path);
  30.  
  31. var b1 = b.Distinct();
  32.  
  33. foreach (byte a in b1)
  34.  
  35. {
  36.  
  37. Console.WriteLine("Частота появления числа " + a + " равна " + ((float)b.Count(l => l == a) / (float)b.Length));
  38.  
  39. f += -((float)b.Count(l => l == a) / (float)b.Length) * Math.Log((float)b.Count(l => l == a) / (float)b.Length) / Math.Log(2);
  40.  
  41. }
  42.  
  43. Console.WriteLine("Энтропия равна " + f);
  44.  
  45. Console.ReadKey();
  46.  
  47. }
  48.  
  49. }
  50.  
  51. }
  52. /*using System;
  53. using System.Collections.Generic;
  54. using System.Linq;
  55. using System.Text;
  56. using System.IO;
  57.  
  58.  
  59. namespace Structure
  60. {
  61. class Student
  62. {
  63. string sname, name;
  64. int date, mark;
  65.  
  66. public Student(string a, string b, int c, int d)
  67. {
  68. sname = a;
  69. name = b;
  70. date = c;
  71. mark = d;
  72. }
  73.  
  74. public string show()
  75. {
  76. return String.Format("Student:\n\tName: {0}\n\tSurname: {1}\n\tDate of birth: {2}\n\tAverage mark: {3}", name, sname, date, mark);
  77. }
  78. }
  79.  
  80.  
  81. class Program
  82. {
  83. public static void Main(string[] args)
  84. {
  85.  
  86. //File.WriteAllText("F:\\input.txt", "surush surush 1 2");
  87.  
  88.  
  89. // string s;
  90. /* StreamReader reader = new StreamReader( "F:\\input.txt" );
  91. StreamWriter writer = new StreamWriter("F:\\Grouop.bin");
  92. while (true)
  93. {
  94. s = Console.ReadLine();
  95. if (s[0] == ' ')
  96. break;
  97. s = s + "\r\n";
  98. Console.WriteLine(s);
  99. writer.WriteLine(s);
  100. }
  101. writer.Close();
  102.  
  103. string[] lines = File.ReadAllLines("F:\\Grouop2.bin");
  104. StreamWriter writer = new StreamWriter("F:\\output.txt");
  105. for (int i = 0; i < lines.Length; i++)
  106. {
  107. Console.WriteLine(lines[i]);
  108. writer.WriteLine(lines[i]);
  109. }
  110. writer.Close();
  111. Console.Write("Press any key to continue . . . ");
  112. Console.ReadKey(true);
  113. }
  114. }
  115. }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement