Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.96 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5.  
  6. namespace ut
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. #region 1. feladat
  13. Console.WriteLine("1. feladat");
  14. Console.WriteLine();
  15.  
  16. StreamReader sr = new StreamReader("forgalom.txt");
  17. int autokszama = int.Parse(sr.ReadLine());
  18. List<int> ora = new List<int>();
  19. List<int> perc = new List<int>();
  20. List<int> msp = new List<int>();
  21. List<int> athaladas = new List<int>();
  22. List<char> varos = new List<char>();
  23.  
  24. while (!sr.EndOfStream)
  25. {
  26.  
  27. string[] tmp = sr.ReadLine().Split(" ");
  28. ora.Add(int.Parse(tmp[0]));
  29. perc.Add(int.Parse(tmp[1]));
  30. msp.Add(int.Parse(tmp[2]));
  31. athaladas.Add(int.Parse(tmp[3]));
  32. varos.Add(char.Parse(tmp[4]));
  33.  
  34. }
  35. Console.WriteLine("Az adatok beolvasás kész.");
  36. Console.WriteLine();
  37. #endregion
  38.  
  39. #region 2. feladat
  40. Console.WriteLine("2. feladat");
  41. Console.WriteLine();
  42. Console.WriteLine("Adja meg a jármű sorszámát!");
  43. int sszam = int.Parse(Console.ReadLine());
  44. if (varos[sszam - 1] == 'F')
  45. {
  46. Console.WriteLine("A {0}.auto Felső város felé haladt.", sszam);
  47. }
  48. else if (varos[sszam - 1] == 'A')
  49. {
  50. Console.WriteLine("A {0}.auto Alsó város felé haladt.", sszam);
  51. }
  52. Console.WriteLine();
  53. #endregion
  54.  
  55. #region 3. feladat
  56. Console.WriteLine("3. feladat");
  57. Console.WriteLine();
  58. int utolso = varos.LastIndexOf('F');
  59. int utolsoelotti = 0;
  60. for (int i = 0; i < utolso; i++)
  61. {
  62. if (varos[i] == 'F')
  63. {
  64. utolsoelotti = i;
  65. }
  66. }
  67. int utolsoido = ora[utolso] * 3600 + perc[utolso] * 60 + msp[utolso];
  68. int utolsoelottiido = ora[utolsoelotti] * 3600 + perc[utolsoelotti] * 60 + msp[utolsoelotti];
  69. Console.WriteLine("A Felső város irányába tartó utolsó két jármű {0} másodperc különbséggel érte el az útszakasz kezdetét.", utolsoido - utolsoelottiido);
  70. Console.WriteLine();
  71. #endregion
  72.  
  73. #region 4. feladat
  74. Console.WriteLine("4. feladat");
  75. Console.WriteLine();
  76. List<int> orak = new List<int>();
  77. List<int> felso = new List<int>();
  78. List<int> also = new List<int>();
  79. orak.Add(ora[0]);
  80. for (int i = 1; i < ora.Count; i++)
  81. {
  82. if (ora[i] > ora[i - 1])
  83. {
  84. orak.Add(ora[i + 1]);
  85. }
  86. }
  87. for (int i = 0; i < orak.Count; i++)
  88. {
  89. felso.Add(0);
  90. also.Add(0);
  91. }
  92. for (int i = 0; i < orak.Count; i++)
  93. {
  94. for (int j = 0; j < ora.Count; j++)
  95. {
  96. if (orak[i] == ora[j])
  97. {
  98. if (varos[j] == 'F')
  99. {
  100. felso[i]++;
  101. }
  102. else if (varos[j] == 'A')
  103. {
  104. also[i]++;
  105. }
  106. }
  107. }
  108. }
  109. for (int i = 0; i < orak.Count; i++)
  110. {
  111. Console.WriteLine("Óra: {0} A: {1} F: {2}", orak[i], also[i], felso[i]);
  112. }
  113. Console.WriteLine();
  114. #endregion
  115.  
  116. #region 5.feladat
  117. Console.WriteLine("5.feladat");
  118. List<double> sebesseg = new List<double>();
  119. List<int> otIndexek = new List<int>();
  120. for (int i = 0; i < athaladas.Count; i++)
  121. {
  122. double tmp = 1000 / athaladas[i];
  123. sebesseg.Add(Math.Round(tmp,2));
  124. }
  125.  
  126. double maxseb = Math.Round(sebesseg.Max(),2);
  127. for (int i = 0; i < athaladas.Count; i++)
  128. {
  129. if (sebesseg[i]==maxseb)
  130. {
  131. otIndexek.Add(i);
  132. }
  133. if (otIndexek.Count==10)
  134. {
  135. break;
  136. }
  137. maxseb=Math.Round(maxseb-0.01,2);
  138. }
  139.  
  140. Console.WriteLine();
  141.  
  142. Console.WriteLine();
  143. #endregion
  144.  
  145. #region 6.feladat
  146. Console.WriteLine("6. feladat");
  147. Console.WriteLine();
  148.  
  149. Console.WriteLine();
  150. #endregion
  151. }
  152. }
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement