Advertisement
Guest User

Untitled

a guest
Mar 6th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.84 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.  
  7. namespace Graphs
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             //read file by line
  14.             String line;
  15.             System.IO.StreamReader file = new System.IO.StreamReader(@"D:\users\boris\documents\visual studio 2013\Projects\Graphs\Graphs\input.txt");
  16.  
  17.             String header_line = line = file.ReadLine();//read first line
  18.             String[] segments = header_line.Split(' ');
  19.  
  20.             int tops = Convert.ToInt32(line.Split(' ')[0]);
  21.             int sides = Convert.ToInt32(line.Split(' ')[1]);
  22.  
  23.             int[,] matrix = new int[tops, tops];
  24.             for (int i = 0; i < matrix.GetLength(0); i++)
  25.             {
  26.                 for (int j = 0; j < matrix.GetLength(1); j++)
  27.                 {
  28.                     matrix[i, j] = 0;
  29.                 }
  30.             }
  31.             while ((line = file.ReadLine()) != null)
  32.             {
  33.  
  34.                     int i = Convert.ToInt32(line.Split(' ')[0]) - 1;
  35.                     int j = Convert.ToInt32(line.Split(' ')[1]) - 1;
  36.                     matrix[i, j] = 1;
  37.                
  38.             }
  39.             line = "";
  40.             using (System.IO.StreamWriter outputfile = new System.IO.StreamWriter(@"D:\users\boris\documents\visual studio 2013\Projects\Graphs\Graphs\output.txt"))
  41.             {
  42.                 for (int i = 0; i < matrix.GetLength(0); i++)
  43.                 {
  44.                     for (int j = 0; j < matrix.GetLength(1); j++)
  45.                     {
  46.                         line = line + Convert.ToString(matrix[i, j]) + " ";
  47.  
  48.                     }
  49.                     outputfile.WriteLine(line);
  50.                     line = "";
  51.                 }
  52.             }
  53.  
  54.            
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement