gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 17:41:31 26 4
gpt4 key购买 nike

我必须使用下一个文本文件:

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

或者如果我有 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)

第二阶段:搜索和输出

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

这是您要找的吗?

关于c - 如何从文本文件中恢复信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21069406/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com