Advertisement
kabanosiek

wczytywanie z pliku i wypisywanie

Oct 25th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace mozesieuda
  9. {
  10.     public static class FilesStream
  11.     {
  12.         public static char[,] map = null;
  13.         public static Treenode mainnode = null;
  14.         public static LinkedList<Treenode> list;
  15.         public static int rows, columns;
  16.         public static int counter=0;
  17.         public static void GetInput()
  18.         {
  19.             rows = 0;
  20.             columns = 0;
  21.             map = null;
  22.             int z = 0;
  23.             try
  24.             {
  25.                 using (StreamReader str = new StreamReader("in3.txt"))
  26.                 {
  27.                     string line = "";
  28.                     while ((line = str.ReadLine()) != null)
  29.                     {
  30.                         if (line.Length == columns)
  31.                         {
  32.                             for (int i = 0; i < columns; i++)
  33.                             {
  34.                                 map[z, i] = line[i];
  35.                                 if(line[i]=='x' && z!=0&& z!=rows-1 && i!=0 && i!=columns-1)
  36.                                 {
  37.                                     list.AddLast(new Treenode {currentrow=z,currentcolumn=i});
  38.                                 }
  39.                             }
  40.                             z++;
  41.                         }
  42.                         else
  43.                         {
  44.                             var split = line.Split(' ');
  45.                             list = new LinkedList<Treenode>();
  46.                             int.TryParse(split[0], out rows);
  47.                             int.TryParse(split[1], out columns);
  48.                             map = new char[rows, columns];
  49.  
  50.                         }
  51.                     }
  52.                 }
  53.             }
  54.             catch (IOException)
  55.             {
  56.                 Console.WriteLine("File not found");
  57.                 throw;
  58.             }
  59.  
  60.         }
  61.         public static void Output(int? island, int? river)
  62.         {
  63.             using (StreamWriter stw = new StreamWriter("out3.txt"))
  64.             {
  65.                 stw.Write(island + " " + river);
  66.             }
  67.         }
  68.     }
  69.    
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement