基本字符串压缩

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Zipper:
    def zipString(self, iniString):
        nlen = len(iniString)
        rest =[]
        i = 0
        endflag = 0
        while i < (nlen-1):
            for j in range(i+1, nlen):
                if iniString[i] == iniString[j]:
                    continue
                else:
                     rest.append((iniString[i], i, j))
                     endflag = j
                     break
            i = j
 
        rest.append((iniString[endflag], endflag, nlen))
        resStr = ""
        for item in rest:
            resStr += (item[0] + str(item[2]-item[1]))
 
        if len(resStr) >= nlen:
            return iniString
        else:
            return resStr
a = Zipper()
print a.zipString('aabcccccaaa')
 
b = Zipper()
print b.zipString('welcometonowcoderrrrr')
 
c = Zipper()
bstr= c.zipString('qwertyuioplkjhgfdsAzxcvbNM')
print type(bstr)