SHARE
TWEET

Untitled

a guest Dec 5th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import re
  2.  
  3. def read_from_file():
  4.     file = open("input.txt", "r")
  5.     first_line = file.readline()
  6.     first_line = re.sub("\[|,|\]| ", "", first_line)
  7.     print(first_line)
  8.     graf = {}
  9.     l = []    
  10.     for ch in first_line:
  11.         if ch != '\n':
  12.             l.append(int(ch))
  13.     print(l)
  14.  
  15.     graf["noduri"] = l;
  16.     print(graf)
  17.  
  18.     #muchii
  19.     second_line = file.readline()
  20.     second_line = re.sub("\[|,|\]| |\)|\(", "", second_line)
  21.     print(second_line)
  22.     t = ()
  23.     l2 = []
  24.     for i in range(len(second_line)-2):
  25.         ch1 = second_line[i]
  26.         ch2 = second_line[i+1]
  27.         t = (int(ch1), int(ch2))
  28.         l2.append(t)
  29.         i = i+1
  30.     print(l2)
  31.     graf["muchii"] = l2
  32.     print(graf)
  33.     return graf
  34.  
  35. def matrice(graf):
  36.     n = len(graf.get("noduri"))
  37.     matrice = []
  38.     for i in range(n):
  39.         matrice.append([0] * n)
  40.     print(matrice)
  41.     t = ()
  42.     for linie in range(n):
  43.         for coloana in range(n):
  44.             t = (linie+1, coloana+1)
  45.             if t in graf["muchii"]:
  46.                 matrice[linie][coloana] = 1
  47.             else:
  48.                 matrice[linie][coloana] = 0
  49.     print(matrice)
  50.  
  51. if __name__ == "__main__":
  52.     graf = read_from_file()
  53.     matrice(graf)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top