题目:
r=$((100*$RANDOM/32767));paste -d '\t' <(seq 11 $r 1000) <(seq 1000 -$r 11 |sort -R) > file1 ; sed 's/\t//g' file1 > file2
file1 共两列, 第一列是按等差进行排序的, 第二列是随机排序的, 现在不小心将file1中的空白都删掉了, 变得只有一列了, 如file2, 现在需要将file1进行还原.
[root@localhost ~]#
[root@localhost ~]# cat file1
11 740
76 480
141 155
206 935
271 545
336 870
401 1000
466 350
531 285
596 675
661 25
726 805
791 90
856 415
921 220
986 610
[root@localhost ~]# cat file2
11740
76480
141155
206935
271545
336870
4011000
466350
531285
596675
66125
726805
79190
856415
921220
986610
#!/usr/bin/python
# coding:utf8
def rstripenter():
f = []
with open('file2') as fd:
for r in fd: f.append(r.rstrip())
return f
def exhmethod(x):
y = z = x
H1 = []
H2 = []
result = None
for n in range(len(h)-2):
h1 = h[n][0:x]
H1.append(h1)
while True:
h2 = h[n+1][0:y]
v1 = int(h2)+int(h2)-int(h1)
z = len(str(v1))
h3 = h[n+2][0:z]
if v1 != int(h3):
y += 1
else:
H2.append(h[n][x:])
x = len(h2)
break
if len(h[n+1][0:y]) == len(h2):
result = False
break
if result is False:
break
else:
result = True
H1.append(h2)
H1.append(h3)
H2.append(h[n+1][x:])
H2.append(h[n+2][x:])
if result is True:
for r in zip(H1, H2): print '\t'.join(r)
return result
h = rstripenter()
for n in range(1, len(h[0])):
if exhmethod(n):
break
n+=1
只要是按等差排序的, 都能整出来.