梦幻 | Reopening of Dream Python3 题解

· · 题解

按题意模拟

1.普通人

普通人的代码一定是最正常的格式。

freopen("<title>.in","r",stdin);
freopen("<title>.out","w",stdout);

所以只需要拼接出标准的 freopen 语句进行比较。

read == 'freopen("' + title[j] +'.in","r",stdin);' \
and write == 'freopen("' + title[j] + '.out","w",stdout);'

2.见祖宗人

用切片 [:-10] 和 [-2:] 获取输入的开头和结尾进行比较。

(len(read)>=10 and read[:10] == "//freopen(" and read[-2:]==");") \
or (len(write)>=10 and write[:10] == "//freopen(" and write[-2:]==");")

3.乐子人

其它所有情况都属于乐子人。

判断优先级

参考第一篇题解将普通人定为 type1 ,见祖宗人为 type3 ,乐子人为 type2 。可以写出如下的判断。

intype = 2 # 每两行语句用一个intype储存判断结果
read = input()
write = input()
if read == 'freopen("' + title[j] + '.in","r",stdin);' \
  and write == 'freopen("' + title[j] + '.out","w",stdout);':
    intype = 1
elif (len(read)>=10 and read[:10] == "//freopen(" and read[-2:]==");") \
    or (len(write)>=10 and write[:10] == "//freopen(" and write[-2:]==");"):
    intype = 3
outtype = max(outtype,intype) # 把选手设为优先级较大的那一类

注意

每 2m+1 行中第一行为空行,要用 input() 跳过空行。

参考代码

t = int(input())
n = input().split(sep=" ")
m = int(n[1])
n = int(n[0])

title = []
for i in range(m):
    title.append(input())

index = 0
for i in range(n):
    outtype = 1
    input() # 跳过空行
    for j in range(m):
        intype = 2
        read = input()
        write = input()
        if read == 'freopen("' + title[j] + '.in","r",stdin);' \
           and write == 'freopen("' + title[j] + '.out","w",stdout);':
            intype = 1
        elif (len(read)>=10 and read[:10] == "//freopen(" and read[-2:]==");") \
              or (len(write)>=10 and write[:10] == "//freopen(" and write[-2:]==");"):
            intype = 3
        outtype = max(outtype,intype)
    if outtype == 1:
        print("PION2202 RP++.")
    elif outtype == 3:
        print("Wrong file operation takes you to your ancestors along with your 3 years' efforts on OI.")
    else:
        print("Good luck and have fun.")