Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. data/a.txt"File_may_be_rewritt..._more_info_inside_this_folder"
  2. ACTUALLY...|YOU|
  3. ACTUALLY..."|"YOU"|"ARE"|"WRONG"|"!!!"|"Actually"|"You_perfectly_understand_what_you_doing"|"But_what_if_we_gonna_send_u_a_message"|"Contains_many_symbols"|"Like_this:"|"..."|"973-eht-namuh-973.com"|"The_secret_message_contains_table...And...?"|"++++++++++[>+>+++>+++++++>++++++++++<<<<-]>>>++++++++.>+++++++++++.+++++.<<++.>>------------.---.+++++++++++++.-------------."|"CaesaR_avwgfw.uge/UMnaIw
  4. Not here
  5. END
  6. CaesaR_avwgfw.uge/UMnaIw"|"01001001_01110100_00100111_01110011_00100000_01110011_01110100_01101001_01101100_01101100_00100000_01110111_01110010_01101111_01101110_01100111_00101110_00100000_01010011_01101111_01110010_01110010_01111001_00101110"|
  7.  
  8. from sys import stdin, stdout
  9.  
  10. def search(fold_ind, file_name):
  11. left, right = -1, len(dr[fold_ind])
  12. while left < right - 1:
  13. mid = (left + right) // 2
  14. if dr[fold_ind][mid][0] < file_name:
  15. left = mid
  16. else:
  17. right = mid
  18.  
  19. file_index = right
  20. return file_index
  21.  
  22.  
  23. def dfs_count(fold_ind, file_name):
  24. count = 0
  25. stack = [fold_ind]
  26. while len(stack) > 0:
  27. v = stack.pop()
  28. for file in dr[v]:
  29. if len(file) == 1:
  30. stack.append(fold_index[file[0]])
  31. elif file[0] == file_name:
  32. count += 1
  33. return count
  34.  
  35.  
  36. n = int(stdin.readline())
  37. dr = [[] for i in range(n)] #директория
  38. par = {'/': '/'} #родитель каждой папки
  39. fold_index = {} #индексы по названиям
  40. fold_name = [] #названия по индексам
  41. cur = 0 #текущая папка
  42. txt_names = set()
  43.  
  44. for i in range(n):
  45. t = stdin.readline().split()
  46.  
  47. name = t[0][:-1]
  48. fold_index[name] = i
  49. fold_name.append(name)
  50.  
  51. count = int(t[1])
  52. for j in range(count):
  53. if t[2+j][-4:] == '.txt':
  54. dr[i].append([t[2+j], ''])
  55. txt_names.add(t[2+j])
  56. else:
  57. par[t[2+j]] = name
  58. dr[i].append([t[2+j]])
  59.  
  60. if 'trash' in fold_index.keys() and 'data' in fold_index.keys() and par['data'] == 'trash':
  61. flag = True
  62. else:
  63. flag = False
  64. ans = ''
  65.  
  66. m = int(stdin.readline())
  67. for i in range(m):
  68. t = stdin.readline()
  69. folder_name = ''
  70. file_nm = ''
  71. txt = ''
  72. stage = 0
  73.  
  74. for s in t:
  75. if stage == 0:
  76. if s == '/':
  77. stage += 1
  78. if len(folder_name) == 0:
  79. folder_name = '/'
  80. else:
  81. folder_name += s
  82. elif stage == 1:
  83. if s == ':':
  84. stage += 1
  85. else:
  86. file_nm += s
  87. elif stage < 4:
  88. stage += 1
  89. else:
  90. if s == '"':
  91. break
  92. else:
  93. txt += s
  94.  
  95. ind = fold_index[folder_name]
  96. dr[ind][search(ind, file_nm)][1] = txt
  97.  
  98. massiv = []
  99. q = int(stdin.readline())
  100. for i in range(q):
  101. t = stdin.readline().split()
  102. if t[0] == 'echo' and len(t) == 2:
  103. massiv.append(t[1][1:-1])
  104. elif t[0] == 'ls':
  105. for file in dr[cur]:
  106. massiv.append(file[0])
  107. elif t[0] == 'cd':
  108. if t[1] == '..':
  109. cur = fold_index[par[fold_name[cur]]]
  110. else:
  111. cur = fold_index[t[1]]
  112. elif t[0] == 'cat':
  113. massiv.append(dr[cur][search(cur, t[1])][1])
  114. elif t[0] == 'echo':
  115. if flag:
  116. if t[3][1] == t[3][1].upper():
  117. ans += t[3] + '|'
  118. dr[cur][search(cur, t[2])][1] = t[3][1:-1]
  119. elif t[0] == 'count':
  120. if t[1] in txt_names:
  121. massiv.append(str(dfs_count(cur, t[1])))
  122. else:
  123. massiv.append('0')
  124. if flag:
  125. stdout.write(ans[510:] + '\n')
  126. else:
  127. for i in massiv:
  128. stdout.write(i + '\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement