Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. #funkcje ----------------------------
  2. import math
  3. def ReadMatrix(data): #wczytuje macierz
  4. row = list(map(int, data.split())) #mapuje pierwszy string na liste liczb
  5. size = len(row) #liczy ile ma być wierzchołków
  6. matrix = []
  7. matrix.append(row)
  8. i = 1
  9.  
  10. while i < size:
  11. data = input()
  12. row = list(map(int, data.split()))
  13. matrix.append(row)
  14. i+=1
  15. return matrix
  16.  
  17.  
  18. def PrintMatrix(data): #drukuje macierz
  19. for vert in data:
  20. print(*vert)
  21.  
  22. def CountVertices(data): #zwraca liczbe wierzchołków
  23. vert = len(data)
  24. return vert;
  25.  
  26. def CountEdges(data): #zwraca liczbe krawędzi
  27. size = len(data)
  28. x = 0
  29. y = 0
  30. z = 1
  31. edges = 0;
  32. while x < size:
  33. while(y < z):
  34. if data[x][y] > 0:
  35. edges += 1
  36. y += 1
  37. y = 0
  38. z +=1
  39. x +=1
  40. return edges
  41. def checkZero(values):
  42. counter = 0
  43. for v in values:
  44. if not v ==0:
  45. counter+=1
  46. return counter
  47. def countStopien(matrix):
  48. x=[]
  49. for i in matrix:
  50. x.append(checkZero(i))
  51. return x
  52. def average(vert,stopnie):
  53. return sum(stopnie)/vert
  54.  
  55. def pelny(matrix):
  56. counter =0
  57. for i in matrix:
  58. if not i[counter] == 0:
  59. return False
  60. counter2=0
  61. for j in i:
  62. if not counter2 == counter and j == 0:
  63. return False
  64. counter2+=1
  65. counter+=1
  66. return True
  67.  
  68.  
  69. def cykl(matrix):
  70. if matrix[0][0]==matrix[-1][-1]:
  71. return True
  72. return False
  73. def wypisz():
  74. if pelny(matrix):
  75. print("Jest Pełny")
  76. return
  77. if sciezka(stopnie):
  78. print("Sciezka")
  79. return
  80. if cykl(matrix):
  81. print("Cykl")
  82. return
  83.  
  84.  
  85. def sciezka(stopnie):
  86. if stopnie[0] == stopnie[-1] and stopnie[0] == 1:
  87. return True
  88. return False
  89. def drzewo()
  90.  
  91. #program --------------------------
  92.  
  93. if __name__ == '__main__':
  94. data = input()
  95. matrix = ReadMatrix(data)
  96. vert = CountVertices((matrix))
  97. edges = CountEdges(matrix)
  98. stopnie=countStopien(matrix)
  99.  
  100. print("Ilość wierzchołków: ", vert)
  101. print("Ilość krawędzi: ", edges)
  102. print("Stopnie wierzchołków:", " ".join(str(stopnie)))
  103. print("Średni stopień:", average(vert,stopnie))
  104. wypisz()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement