Guest User

Untitled

a guest
May 27th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. class zigzagconv:
  2. def convert(self,s,numrows):
  3. firstcalcfactor =self.calcadditionfactor(numrows)
  4. difffactor = []
  5. if(numrows == 0):
  6. print ('')
  7. return ''
  8. if(numrows==1):
  9. print(s)
  10. return(s)
  11.  
  12. if(s != '' and numrows !=0):
  13. for row in range(numrows,0,-1):
  14. if(row ==1 or row==numrows):
  15. difffactor.append(firstcalcfactor)
  16. else:
  17. difffactor.append(self.calcadditionfactor(row))
  18. #print(difffactor)
  19. strarr=[]
  20. for i in range(0,len(s)+firstcalcfactor+1,firstcalcfactor+1):
  21. #print(strarr)
  22. if(i == 0):
  23. afrarr = []
  24. afrarr.append(s[i])
  25. strarr.append(afrarr)
  26. else:
  27. if(i <len(s)):
  28. strarr[0].append(s[i])
  29. for row in range(1,numrows-1):
  30. if(i == 0):
  31. afrarr2 = []
  32. if((i+row)<len(s)):
  33. afrarr2.append(s[i+row])
  34. if(i+row+difffactor[row]+1<len(s)):
  35. afrarr2.append(s[i+row+difffactor[row]+1])
  36. if(len(afrarr2)>0):
  37. strarr.append(afrarr2)
  38. else:
  39. if((i+row)<len(s)):
  40. strarr[row].append(s[i+row])
  41. if(i+row+difffactor[row]+1<len(s)):
  42. strarr[row].append(s[i+row+difffactor[row]+1])
  43.  
  44. if(i == 0):
  45. afrarr = []
  46. afrarr.append(s[i+numrows-1])
  47. strarr.append(afrarr)
  48. else:
  49. if(i+numrows-1<len(s)):
  50. strarr[numrows-1].append(s[i+numrows-1])
  51. finalstring =''
  52.  
  53. for i in range(numrows):
  54. finalstring=finalstring+ (''.join(strarr[i]))
  55. print(finalstring)
  56. return finalstring
  57. else:
  58. print('')
  59. return ''
  60.  
  61. def calcadditionfactor(self,numrows):
  62. return (numrows-1)*2-1
  63.  
  64. def inputfunc():
  65. ip1 = input()
  66. ip2 = input()
  67. ip3 = input()
  68. return (ip1, ip2 ,ip3);
  69.  
  70. def processingfunc(ip1,ip2,ip3):
  71. #Write code for the problem here
  72.  
  73. return (ip1,ip2,ip3)
  74.  
  75. def main():
  76. # ip1,ip2,ip3 =inputfunc()
  77. # op1,op2,op3 = processingfunc(ip1,ip2,ip3)
  78. # if(op1 != None or op1 != ''):
  79. # print(op1)
  80. # if(op2 != None or op2 != ''):
  81. # print(op3)
  82. # if(op3 != None or op3 != ''):
  83. # print(op3)
  84. zisk = zigzagconv()
  85. zisk.convert("PAYPALISHIRING",4)
  86.  
  87. main()
Add Comment
Please, Sign In to add comment