Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class zigzagconv:
- def convert(self,s,numrows):
- firstcalcfactor =self.calcadditionfactor(numrows)
- difffactor = []
- if(numrows == 0):
- print ('')
- return ''
- if(numrows==1):
- print(s)
- return(s)
- if(s != '' and numrows !=0):
- for row in range(numrows,0,-1):
- if(row ==1 or row==numrows):
- difffactor.append(firstcalcfactor)
- else:
- difffactor.append(self.calcadditionfactor(row))
- #print(difffactor)
- strarr=[]
- for i in range(0,len(s)+firstcalcfactor+1,firstcalcfactor+1):
- #print(strarr)
- if(i == 0):
- afrarr = []
- afrarr.append(s[i])
- strarr.append(afrarr)
- else:
- if(i <len(s)):
- strarr[0].append(s[i])
- for row in range(1,numrows-1):
- if(i == 0):
- afrarr2 = []
- if((i+row)<len(s)):
- afrarr2.append(s[i+row])
- if(i+row+difffactor[row]+1<len(s)):
- afrarr2.append(s[i+row+difffactor[row]+1])
- if(len(afrarr2)>0):
- strarr.append(afrarr2)
- else:
- if((i+row)<len(s)):
- strarr[row].append(s[i+row])
- if(i+row+difffactor[row]+1<len(s)):
- strarr[row].append(s[i+row+difffactor[row]+1])
- if(i == 0):
- afrarr = []
- afrarr.append(s[i+numrows-1])
- strarr.append(afrarr)
- else:
- if(i+numrows-1<len(s)):
- strarr[numrows-1].append(s[i+numrows-1])
- finalstring =''
- for i in range(numrows):
- finalstring=finalstring+ (''.join(strarr[i]))
- print(finalstring)
- return finalstring
- else:
- print('')
- return ''
- def calcadditionfactor(self,numrows):
- return (numrows-1)*2-1
- def inputfunc():
- ip1 = input()
- ip2 = input()
- ip3 = input()
- return (ip1, ip2 ,ip3);
- def processingfunc(ip1,ip2,ip3):
- #Write code for the problem here
- return (ip1,ip2,ip3)
- def main():
- # ip1,ip2,ip3 =inputfunc()
- # op1,op2,op3 = processingfunc(ip1,ip2,ip3)
- # if(op1 != None or op1 != ''):
- # print(op1)
- # if(op2 != None or op2 != ''):
- # print(op3)
- # if(op3 != None or op3 != ''):
- # print(op3)
- zisk = zigzagconv()
- zisk.convert("PAYPALISHIRING",4)
- main()
Add Comment
Please, Sign In to add comment