• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Aug 19th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import albero
2.
3. class Albero:
4.      c=0
6.      superstring=[]
7.
8.      def __init__(self,V):
9.         if Albero.c==0:
11.         Albero.c+=1
12.
13.         self.id=V
14.         self.f=[]
15.         self.aiuto=[]
16.
17. def checkson(nIden,Wmax,space,Risultato):
18.      NodoLine  = nIden.center(Wmax,space)
19.      Risultato  = [NodoLine]
20.      return Risultato
21.
22. def Joined(Nodo,TakeStats):
23.     superstring = "\n".join(getStr(Nodo,TakeStats))
24.     return superstring
25.
26.
27. def setup(nSons,subNodos):
28.     widhts=[]
29.
30.
31.     for f in nSons:
32.         subNodos.append(getStr(f,TakeStats))
33.
34.
35.     for x in subNodos:
36.         widhts.append(len(x[0]))
37.
38.     return widhts,subNodos
39.
40.
41.
42. def maxwidht(widths,nIden):
43.
44.     a=0
45.
46.     for x in widths:
47.         a=a+x
48.
49.     Wmax = a + 2*len(widths)
50.     Wmax=Wmax-2
51.
52.     asp = [Wmax,len(nIden)]
53.     Wmax = max(asp)
54.
55.     return Wmax
56.
57.
58. def span(Wmax,subNodos,space,tofind):
59.     c = 0
60.     cont = 0
61.     s=""
62.
63.     for i in range(Wmax):
64.         s+=space
65.
66.     spanlin = list(s)
67.
68.
69.     for a in range(len(subNodos)):
70.         for x in subNodos[a][0]:
71.             if x != space and cont == 0:
72.                 spanlin[c] = tofind
73.                 cont = 1
74.             c += 1
75.         cont = 0
76.         c += 2
77.
78.
79.     spanlin   = "".join(spanlin)
80.     spanlin   = spanlin.center(Wmax,space)
81.
82.     return spanlin
83.
84. def getStr(Nodo,TakeStats):
85.     space=" "
86.     tofind="|"
87.     Risultato  = []
88.     widths = []
89.     subNodos=[]
90.     Stats = TakeStats(Nodo)
91.     nIden=Stats[0]
92.     nSons=Stats[1]
93.
94.
95.
96.     widths,subNodos=setup(nSons,subNodos)
97.
98.     a=0
99.
100.     for x in widths:
101.         a=a+x
102.
103.
104.
105.     Wmax = maxwidht(widths,nIden)
106.
107.
108.     if not nSons:
109.        return checkson(nIden,Wmax,space,Risultato)
110.
111.
112.     spanlin=span(Wmax,subNodos,space,tofind)
113.
114.
115.
116.     a = spanlin.find(tofind)
117.     b  = spanlin.rfind(tofind)
118.     s1=""
119.     for i in range(Wmax):
120.         s1+=space
121.
123.
125.
127.
128.
131.
133.     radLine[medium + 1] = nIden[2-1]
135.
137.
139.
140.     if a == b:
142.
143.     elif a < b:
144.
146.             if z > a and z < b:
148.     integer=int((a+b)/2)
151.     medium = position.find(tofind)
152.
153.
154.
155.     l=len(nSons)
156.     lens=[]
157.     results=[]
158.     s2=""
159.
160.     for i in range(Wmax):
161.         s2+=" "
162.
163.
165.
166.
167.     if l > 1:
168.         Risultato.append(position)
169.     Risultato.append(spanlin)
170.
171.     for x in subNodos:
172.         lens.append(len(x))
173.
174.     maxHeight = max(lens)
175.
176.     subNodos = [ subNodo + [" "*len(subNodo[0])]*(maxHeight-len(subNodo)) for subNodo in subNodos ]
177.
178.     for i in range(maxHeight):
179.         Risultato+=["  ".join([subNodo[i] for subNodo in subNodos]).center(Wmax," ")]
180.
181.     return Risultato
182.
183.
184.
185.
186. if __name__ == '__main___':
187.
188.
189.     n=Albero("05")
190.     n1=Albero("02")
191.     n2=Albero("04")
192.     n3=Albero("06")
193.     n4=Albero("01")
194.     n5=Albero("01")
195.     n6=Albero("02")
196.     n7=Albero("09")
197.     n8=Albero("08")
198.     n9=Albero("02")
199.     n10=Albero("03")
200.     n11=Albero("06")
201.     n12=Albero("02")
202.
203.
204.     n.f=[n1,n2,n3]
205.     n1.f=[n4]
206.     n6.f=[n10,n11]
207.     n2.f=[n5,n6,n7,n8,n12]
208.
209.
210.
211. def es2(r):
212.     return Joined(r,TakeStats)
213.
214. def TakeStats(Nodo):
215.     son = Nodo.f
216.     ide = Nodo.id
217.
218.     tuples = (ide,son)
219.     return tuples
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.

Top