Advertisement
Guest User

Untitled

a guest
Oct 18th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7.  
  8. namespace K1_pvz
  9. {
  10. class Program
  11. {
  12. public const int CmaxGatves = 1000;
  13. static void Main(string[] args)
  14. {
  15. Gatve[] Gatves = new Gatve[CmaxGatves];
  16. string coment = "pradinių duomenų lentelė";
  17. int ss = 0;
  18. int kiek;
  19. string fv = "Kaunas.txt";
  20. Ivesti(fv, Gatves, out kiek);
  21. IlgiausiaGatve(Gatves, kiek);
  22. GatviuSkaicius(Gatves, kiek, ss);
  23. GatviuVidutinisIlgis(Gatves, kiek);
  24. Spausdinti(Gatves, kiek, coment);
  25.  
  26. }
  27. static void Ivesti(string fv, Gatve[] Gatves, out int kiek)
  28. {
  29. StreamReader reader = new StreamReader(fv);
  30. kiek = 0;
  31. string line;
  32. while ((line = reader.ReadLine()) != null)
  33. {
  34. string[] dalys = line.Split(';');
  35. string pavadinimas = dalys[0];
  36. int ilgis = Convert.ToInt32(dalys[1]);
  37. int saligatviai = Convert.ToInt32(dalys[2]);
  38. Gatve gatve = new Gatve(pavadinimas, ilgis, saligatviai);
  39. Gatves[kiek++] = gatve;
  40. }
  41. }
  42. // Randa ir grąžina ilgiausios gatvės indeksą masyve Gatves(kiek)
  43. static int IlgiausiaGatve(Gatve[] Gatves, int kiek)
  44. {
  45. int ilgiausia = Gatves[0].Ilgis;
  46. for (int i = 0; i < kiek; i++)
  47. {
  48. if (Gatves[i].Ilgis > ilgiausia)
  49. {
  50. ilgiausia = Gatves[i].Ilgis;
  51. }
  52. }
  53. return ilgiausia;
  54. }
  55. // Randa ir grąžina, kiek yra gatvių masyve Gatves(kiek),kurių šaligatvių skaičius ss
  56. static int GatviuSkaicius(Gatve[] Gatves, int kiek, int ss)
  57. {
  58. int neturiSal = Gatves[0].Saligatviai;
  59. for (int i = 0; i < kiek; i++)
  60. {
  61. if (Gatves[i].Ilgis == ss)
  62. {
  63. neturiSal = Gatves[i].Saligatviai;
  64. }
  65.  
  66. }
  67. return neturiSal;
  68. }
  69. static double GatviuVidutinisIlgis(Gatve[] Gatves, int kiek)
  70. {
  71. int visasILgis = Gatves[0].Ilgis;
  72. for (int i = 0; i < kiek; i++)
  73. {
  74. visasILgis += Gatves[i].Ilgis;
  75. }
  76. return visasILgis;
  77. }
  78. static void Spausdinti(Gatve[] Gatves, int kiek, string coment)
  79. {
  80. string[] eilutes = new string[CmaxGatves];
  81. //int k = 0;
  82. Console.WriteLine("{0}", coment);
  83. Console.WriteLine("---------------------------------");
  84. Console.WriteLine("|Gatve |Ilgis |Saligatviai|");
  85. Console.WriteLine("---------------------------------");
  86. for (int i = 0; i < kiek; i++)
  87. {
  88. Console.WriteLine("|{0, -9}|{1, -9}|{2, -11}|", Gatves[i].GatvesPav, Gatves[i].Ilgis, Gatves[i].Saligatviai);
  89. Console.WriteLine("---------------------------------");
  90.  
  91. }
  92. Console.WriteLine("Ilgiausia gatve: {0} {1}");
  93.  
  94.  
  95. }
  96.  
  97.  
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement