明白文件的含义了。c后面的数字代表有几块儿。newLines = []
blockNewLines = []
firstBlockLine = False
oneBlockTotalLines = 0
nBlocks = 0
for line in lines:
if line.startswith('c'):
ch,cv = line.strip().split()
nBlocks = int(cv)
blockNewLines.append('c ?') # it's just a placeholder
firstBlockLine = True
oneBlockTotalLines = 0
elif nBlocks > 0:
if firstBlockLine:
theBlockLines = int(line.strip())
oneBlockTotalLines += theBlockLines
firstBlockLine = False
continue
if theBlockLines > 0:
blockNewLines.append(line + "\n")
theBlockLines -= 1
if theBlockLines
nBlocks -= 1
firstBlockLine = True
if nBlocks
blockNewLines.append('\n')
blockNewLines[0] = 'c %d\n' % oneBlockTotalLines
newLines.extend(blockNewLines)
blockNewLines = []
print "".join(newLines)