C 如何从文本文件恢复信息
我必须处理下一个文本文件:C 如何从文本文件恢复信息,c,C,我必须处理下一个文本文件: ABA INH 1806 2 0 2 ADCA IMM 89ii 1 1 2 DIR 99dd 1 1 2 EXT B9hhll 1 2 3 IDX A9xb 1 1 2 IDX1 A9xbff 1 2 3
ABA INH 1806 2 0 2
ADCA IMM 89ii 1 1 2
DIR 99dd 1 1 2
EXT B9hhll 1 2 3
IDX A9xb 1 1 2
IDX1 A9xbff 1 2 3
IDX2 A9xbeeff 1 3 4
[D,IDX] A9xb 1 1 2
[IDX2] A9xbeeff 1 3 4
ADCB IMM C9ii 1 1 2
DIR D9dd 1 1 2
EXT F9hhll 1 2 3
IDX E9xb 1 1 2
IDX1 E9xbff 1 2 3
IDX2 E9xbeeff 1 3 4
[D,IDX] E9xb 1 1 2
[IDX2] E9xbeeff 1 3 4
ADDA IMM 8Bii 1 1 2
DIR 9Bdd 1 1 2
EXT BBhhll 1 2 3
IDX ABxb 1 1 2
IDX1 ABxbff 1 2 3
IDX2 ABxbeeff 1 3 4
[D,IDX] ABxb 1 1 2
[IDX2] ABxbeeff 1 3 4
ADDB IMM CBii 1 1 2
DIR DBdd 1 1 2
EXT FBhhll 1 2 3
IDX EBxb 1 1 2
IDX1 EBxbff 1 2 3
IDX2 EBxbeeff 1 3 4
[D,IDX] EBxb 1 1 2
[IDX2] EBxbeeff 1 3 4
我要做的第一件事是设计一个搜索codop ABA、ADCA、ADCB,。。。为此,我创建了一个只包含codop的链表
在链表上找到codop后,您必须打印所有剩余信息,例如,如果我有codop ABA,则必须打印:
INH 18062 02
或者如果我有codop ADDA,它会打印:
ADDA IMM 8Bii 1 1 2
DIR 9Bdd 1 1 2
EXT BBhhll 1 2 3
IDX ABxb 1 1 2
IDX1 ABxbff 1 2 3
IDX2 ABxbeeff 1 3 4
[D,IDX] ABxb 1 1 2
[IDX2] ABxbeeff 1 3 4
我如何设计一种算法,在搜索后恢复codop的所有信息,无论codop只有一行信息还是多行信息??尽管链接列表中不包含这些信息,但我创建了一个链接列表,因为我认为它更适合用于研究算法以下是伪代码: 第1阶段,建立输入字典:
codops = {} # dictionary data type, where each entry contains an array
cur = [] # array of currently processed codop
for each line of input:
codop = first word in positions 1-8 # adjust accordingly
# for a new codop, add a new entry to the dictionary
if codop != _blank_:
cur = [] # allocate new array for this
add cur to codops dictionary with key = codop
append current line to cur (without positions 1-8)
第2阶段:搜索和输出
input = codop to search
using the codops dictionary, lookup the key=input in the codops dictionary
if the key is in codops:
print all the lines contained in the array returned
else:
print "not found" message
这就是您要找的吗?如果您一直在读取文件的位置,例如ftell或fgetpos,则可以很容易地从文件中恢复它。