货物存储

简单 解决次数: 189 提交次数: 497 内存限制: 256MB 时间限制: 1000ms
链表

货物存储

提交数: 497, 通过率: 38.03%, 平均分: 41.45

题目描述:

某工厂有若干种货物存储在仓库,仓库有m(编号为0~m-1)个货柜,每个货柜存放一件货物。管理员可以入库、出库等操作,每次操作对象有货物名称和数量,入库时从0号到m-1号找到空的货柜放人仓库,出库时一样按序取出。

如仓库有m=10个货柜,依次进行以下3次操作:

入库:[[‘A’,3],[‘B',1],表示把货物A入库3件,货物B入库1件;

出库:[[‘A’,1]],表示把货物A出库1件;

入库:[[‘C’,2],[‘A’,1]],表示把货物C入库2件,货物A入库1件

操作结束后,仓库的存储模拟视图如第15-1图所示:

0 1 2 3 4 5 6 7 8 9
C A A B C A        

 

输入格式:

输入若干行,表示多次操作。

每次操作第一行一个数字,1表示入库 ,2表示出库,3表示查询, 4表示存储现状图 ,5表示退出

对于操作1,2,3,接下来一行字符串表示操作的描述。

参考样例输入。

输出格式:

输出若干行,对于不同操作输出对应信息。

样例:

提示:

知识点:

链表数组:
索引机制:
队列头尾指针:

请完善下列程序:

def findc():
    j = 0
    while ___________________:  #填空1
        j += 1
    if j == m:
        return -1
    c[ j ] = -1
    return j
def putin():
    for i in range(len(a)):
        p = findc()
        if p == -1:
            #仓库已满 
            return
        if a[ i ][ 0 ] not in info: #当前货物没有出现过
            info[ a[ i ][ 0 ] ] = [ p , p ]
        else:
            c[info[ a[ i ][ 0 ] ][ 1 ] ] = p
        for j in range(a[ i ][ 1 ] - 1):
            __________________ # #填空2
            p = c[ p ]
        info[ a[ i ][ 0]][ 1 ] = p
def getout():
    for i in range( len(a) ):
        if a[ i ][ 0 ] not in info:
            print("提示:该货物已无存量")
            continue
        p = info[ a[ i ][ 0 ] ][ 0 ] ; r = 0
        while p != -1 and r < a[ i ][ 1 ]:
            t = c[ p ]; c[ p ] = -2; p = t
            __________________ #填空3
        if p == -1:
            info.pop(a[ i ][ 0 ]) #删除字典中指定的键值对
        else:
            __________________ #填空4
            print("提示:该货物已出库"+str(r)+"件")

m = 20#货柜个数
c = [ -2 ] * m; info = {} #c[i]=-2,表示i号货柜为空
while True:
    #print("仓库管理系统操作菜单:1、入库 2、出库 3、查询 4、存储现状图 5、退出")
    t = int(input()) # "请输入步骤:(1-5)"
    if t==5:
        break
    elif t==1:
        b = input().split(",")
        a = []
        for i in range(0,len(b),2):
            a.append([b[i],int(b[i+1])])
        print(a)
        putin()
    elif t==2:
        b = input().split(",")
        a = []
        for i in range(0,len(b),2):
            a.append([b[i],int(b[i+1])])
        getout()
    elif t==4:
        print(c)
    elif t==3:
        a = input()  #"请输入查询货物:"
        head = ___________ #填空5
        p = head
        while p != -1:
            print("存在柜货号(从0开始):"+str(p+1))
            p = c[p]
时间限制: 1000ms
空间限制: 256MB

我的提交记录

请先登录查看提交记录

登录

497

总提交

189

通过数

38.03%

通过率

61.97%

击败用户

提交分布

38.03%
通过率
正确数 189
错误数 308

解题排行

排名 用户 执行用时 内存消耗 语言 代码长度 提交时间
1
zqrAKIOI
2ms 1,948KB C++ 1057bytes 2024-09-15 13:12:36
2
leafkibo
25ms 16,996KB Python 1998bytes 2025-04-11 08:13:17
3
Kim_Jongun
26ms 16,996KB Python 2009bytes 2025-07-01 09:19:57
4
lhslhs520
26ms 16,996KB Python 1975bytes 2025-04-02 16:17:53
5
zyb666
27ms 16,996KB Python 2008bytes 2025-04-02 15:40:52
6
Toxic_lotus
27ms 16,996KB Python 2008bytes 2025-11-06 09:41:02
7
MAC
27ms 16,996KB Python 2013bytes 2025-04-02 17:26:18
8
Spotless
27ms 16,996KB Python 2009bytes 2025-04-02 15:46:26
9
C_C_greftrLXK
27ms 16,996KB Python 2010bytes 2025-04-02 15:55:31
10
yangzhou
27ms 16,996KB Python 2031bytes 2025-04-14 09:32:08
11
C_113121
27ms 16,996KB Python 1974bytes 2024-04-25 14:10:34
12
hhk
27ms 16,996KB Python 2009bytes 2025-04-02 15:40:36
13
memoriesfly
27ms 16,996KB Python 1963bytes 2024-04-25 14:06:14
14
cindy2007
27ms 16,996KB Python 2075bytes 2024-04-25 14:06:06
15
guozimeng
27ms 16,996KB Python 2018bytes 2024-04-25 14:03:33
16
Mansui
27ms 16,996KB Python 1949bytes 2024-04-25 14:02:06
17
Zcc20071213
27ms 16,996KB Python 2011bytes 2025-04-02 17:06:46
18
hmb
27ms 16,996KB Python 2010bytes 2025-03-30 12:29:10
19
zengtian
27ms 16,996KB Python 2009bytes 2025-04-07 11:37:43
20
dhx202310
27ms 16,996KB Python 2010bytes 2025-03-27 11:26:48

请先登录后提交代码

登录