如何从文本文件中恢复信息

时间:2014-01-11 23:49:17

标签: 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
        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 1806 2 0 2

或如果我有编码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

如何设计一种算法,在搜索后恢复该编码的所有信息,(该编码只有一行信息或更多信息)?即使链接列表中没有包含该信息,我创建了一个链接列表,因为这是我认为它更适合研究算法的方式

1 个答案:

答案 0 :(得分:0)

这是伪代码:

阶段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

这是你在找什么?

相关问题