Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. using System.Threading.Tasks;
  7.  
  8. namespace AnalizaMapyApp
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. string sciezkaDoPliku = "trasaBali.txt";
  15.  
  16.  
  17.  
  18. Console.WriteLine("*** 1. Wczytanie danych ***");
  19. string[] miasta = WczytajMiasta("miasta.txt"); // new string[] {"Kraków","Warszawa","Ujsoły"};
  20. int[] odleglosci = WczytajOdleglosci("odległosci.txt"); // new int[] {32,65};
  21.  
  22.  
  23.  
  24. //Console.WriteLine("\n*** 2. Średnia wartość trasy ***");
  25. //string sr = ObliczSrWartoscTrasy(odleglosci);
  26. //Console.WriteLine(sr);
  27.  
  28. Console.WriteLine("\n*** 3. Najdluzszy odcinek ***");
  29. string trasa = ZlokalizujNajdluzszyOdcinek(miasta, odleglosci);
  30. Console.WriteLine(trasa);
  31.  
  32. //Console.WriteLine("\n*** 4. Wyświetlenie danych ***");
  33. //Wyswietl(miasta, odleglosci);
  34.  
  35.  
  36. }
  37. static string[] WczytajMiasta(string sciezkaDoPliku) //odczytanie tablicy string
  38. {
  39. StreamReader odczytMiast = new StreamReader("miasta.txt");
  40. int n = int.Parse(odczytMiast.ReadLine());
  41. string[] Tablica = new string[n];
  42. for (int i = 0; i < Tablica.Length; i++)
  43. {
  44. Tablica[i] = odczytMiast.ReadLine();
  45. }
  46. odczytMiast.Close();
  47. return Tablica;
  48. }
  49.  
  50. static int[] WczytajOdleglosci(string sciezkaDoPliku) //odczytanie tablicy int
  51. {
  52. StreamReader odczytOdleglosci = new StreamReader("odległosci.txt");
  53.  
  54. string czytajDoKonca = odczytOdleglosci.ReadToEnd();
  55. string[] array = czytajDoKonca.Split('|');
  56. int[] tablica = new int[array.Length];
  57.  
  58. for (int i = 0; i < array.Length; i += 1)
  59.  
  60. {
  61.  
  62. tablica[i] = int.Parse(array[i]);
  63. }
  64.  
  65. return tablica;
  66. }
  67. static string ZlokalizujNajdluzszyOdcinek(string[]miasta , int[] odleglosci)
  68. {
  69.  
  70.  
  71. int max = odleglosci.Max();
  72. int b = Array.IndexOf(odleglosci, max);
  73. int c = b - 1;
  74. int d = b + 1;
  75. string znak1 = "=>";
  76. string znak2 = "=>";
  77. string miasA = miasta[c];
  78. string miasB = miasta[d];
  79. string miasto = max.ToString();
  80.  
  81. string łancuch1 = string.Concat(miasA, znak1, miasto, znak2,miasB);
  82. return łancuch1;
  83. }
  84.  
  85.  
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement