Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4.  
  5. namespace GoogleHascode
  6. {
  7.  
  8. class Book
  9. {
  10. public int id;
  11. public int score;
  12. }
  13. class Library
  14. {
  15. public int id;
  16. public List<int> books = new List<int>();
  17. public int num_of_books;
  18. public int scann_time;
  19. public int scans_per_day;
  20.  
  21. public decimal score;
  22. }
  23.  
  24.  
  25. class Program
  26. {
  27. public static void PrintOutput(List<Library> chosen_libraries)
  28. {
  29. using (var sw = new StreamWriter("output.txt"))
  30. {
  31. sw.WriteLine(chosen_libraries.Count);
  32. for (int i = 0; i < chosen_libraries.Count; i++)
  33. {
  34. sw.WriteLine("{0} {1}", chosen_libraries[i].id, chosen_libraries[i].num_of_books);
  35.  
  36. int j = 0;
  37. for (; j < chosen_libraries[i].num_of_books - 1; j++)
  38. {
  39. sw.Write("{0} ", chosen_libraries[i].books[j]);
  40. }
  41. sw.WriteLine("{0}", chosen_libraries[i].books[j]);
  42. }
  43. }
  44. }
  45.  
  46. public static int ReadInteger(ref StreamReader sr)
  47. {
  48. int number = 0;
  49. int digit = sr.Read();
  50. while ((digit >= 48) && (digit <= 57))
  51. {
  52. number = number * 10 + digit - 48;
  53. digit = sr.Read();
  54. }
  55. return (number);
  56. }
  57.  
  58.  
  59. static void Main(string[] args)
  60. {
  61.  
  62.  
  63. int number_of_books;
  64. int number_of_libraries;
  65. int number_of_days;
  66. List<int> books = new List<int>();
  67. List<Library> libraries = new List<Library>();
  68.  
  69. #region READING INPUT
  70. StreamReader sr = new StreamReader("a_example.txt");
  71. //StreamReader sr = new StreamReader("b_read_on.txt");
  72. //StreamReader sr = new StreamReader("c_incunabula.txt");
  73. //StreamReader sr = new StreamReader("d_tough_choices.txt");
  74. //StreamReader sr = new StreamReader("e_so_many_books.txt");
  75. //StreamReader sr = new StreamReader("f_libraries_of_the_world.txt");
  76.  
  77. //reading first line
  78. string line = sr.ReadLine();
  79. string[] nums_s = line.Split(' ');
  80.  
  81. number_of_books = int.Parse(nums_s[0]);
  82. number_of_libraries = int.Parse(nums_s[1]);
  83. number_of_days = int.Parse(nums_s[2]);
  84.  
  85. //reading second line
  86. for (int i = 0; i < number_of_books; i++)
  87. {
  88. //ReadInteger(sr);
  89.  
  90. books.Add(ReadInteger(ref sr));
  91.  
  92. }
  93.  
  94.  
  95. //reading two lines for libraries
  96. {
  97. long score = 0;
  98. for (int i = 0; i < number_of_libraries; i++)
  99. {
  100. Library lib = new Library();
  101. lib.id = i;
  102. line = sr.ReadLine();
  103. nums_s = line.Split(' ');
  104.  
  105. lib.num_of_books = int.Parse(nums_s[0]);
  106. lib.scann_time = int.Parse(nums_s[1]);
  107. lib.scans_per_day = int.Parse(nums_s[2]);
  108.  
  109.  
  110. if (!(lib.scann_time > number_of_days)) //doba nahrání knihovny je delší jak počet možných dnů
  111. {
  112. //přidám id knížek do knihovny
  113. for (int j = 0; j < lib.num_of_books; j++)
  114. {
  115. int id = ReadInteger(ref sr);
  116. score += books[id];
  117. lib.books.Add(id);
  118. }
  119. lib.score = (score / (decimal)lib.scann_time);
  120. }
  121. libraries.Add(lib);
  122. }
  123. }
  124. #endregion
  125.  
  126. //for (; ; );
  127. PrintOutput(libraries);
  128. }
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement