Advertisement
WadeRollins2710

back_up

Dec 6th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.20 KB | None | 0 0
  1. # 029
  2. import string
  3.  
  4. folder_name = "029XC1"
  5. path = ".\\..\\..\\NTT Code Web\\ntttest\\" + folder_name
  6.  
  7. for i in range(1, 11):
  8.     if (i != 10):
  9.         test_folder = "Test0" + str(i)
  10.     else:
  11.         test_folder = "Test10"
  12.    
  13.     # input
  14.     with open(path + "\\" + test_folder + "\\" + folder_name + ".INP", "r") as f:
  15.         s = f.read()
  16.  
  17.     # process and output
  18.     with open(path + "\\" + test_folder + "\\" + folder_name + ".INP", "w") as f:
  19.         for item in s:
  20.             if item not in string.ascii_letters:
  21.                 s = s.replace(item, "")
  22.         f.write(" ".join(item.capitalize() for item in s.strip().split()))
  23.  
  24. # 030
  25. import string
  26.  
  27. folder_name = "030XC2"
  28. path = ".\\..\\..\\NTT Code Web\\ntttest\\" + folder_name
  29.  
  30. for i in range(1, 11):
  31.     if (i != 10):
  32.         test_folder = "Test0" + str(i)
  33.     else:
  34.         test_folder = "Test10"
  35.    
  36.     # input
  37.     with open(path + "\\" + test_folder + "\\" + folder_name + ".INP", "r") as f:
  38.         s = f.read()
  39.  
  40.     # process and output
  41.     with open(path + "\\" + test_folder + "\\" + folder_name + ".INP", "w") as f:
  42.         for item in s:
  43.             if item not in string.ascii_letters:
  44.                 s = s.replace(item, "")
  45.         lst = item.capitalize() for item in s.strip().split())
  46.         lst.sort()
  47.         f.write(" ". join(lst))
  48.  
  49. # 031
  50. folder_name = "031DX1"
  51. path = ".\\..\\..\\NTT Code Web\\ntttest\\" + folder_name
  52.  
  53. def is_palindrome(s):
  54.     return s == s[::-1]
  55.  
  56. for i in range(1, 11):
  57.     if (i != 10):
  58.         test_folder = "Test0" + str(i)
  59.     else:
  60.         test_folder = "Test10"
  61.    
  62.     # input
  63.     with open(path + "\\" + test_folder + "\\" + folder_name + ".INP", "r") as f:
  64.         s = f.read()
  65.  
  66.     # process and output
  67.     with open(path + "\\" + test_folder + "\\" + folder_name + ".INP", "w") as f:
  68.         index = 0
  69.         while (not is_palindrome(s)):
  70.             s += s[index]
  71.             index += 1
  72.         f.write(s)
  73.  
  74. #032
  75. import sys
  76.  
  77. folder_name = "032DX2"
  78. path = ".\\..\\..\\NTT Code Web\\ntttest\\" + folder_name
  79.  
  80. def is_palindrome(s):
  81.     return s == s[::-1]
  82.  
  83. for i in range(1, 11):
  84.     if (i != 10):
  85.         test_folder = "Test0" + str(i)
  86.     else:
  87.         test_folder = "Test10"
  88.    
  89.     # input
  90.     with open(path + "\\" + test_folder + "\\" + folder_name + ".INP", "r") as f:
  91.         s = f.read()
  92.  
  93.     # process and output
  94.     with open(path + "\\" + test_folder + "\\" + folder_name + ".INP", "w") as f:
  95.         max_value = -sys.maxsize()
  96.         result = ""
  97.         for i in range(0, len(s)):
  98.             for j in range(0, len(s)):
  99.                 substring = s[i:j]
  100.                 if (substring != "") and (is_palindrome(substring)):
  101.                     if (len(substring) > max_value):
  102.                         max_value = len(substring)
  103.                         result = substring
  104.         f.write(substring)
  105.  
  106. # 034
  107. import sys
  108.  
  109. folder_name = "034XC"
  110. path = ".\\..\\..\\NTT Code Web\\ntttest\\" + folder_name
  111.  
  112. for i in range(1, 11):
  113.     if (i != 10):
  114.         test_folder = "Test0" + str(i)
  115.     else:
  116.         test_folder = "Test10"
  117.    
  118.     # input
  119.     with open(path + "\\" + test_folder + "\\" + folder_name + ".INP", "r") as f:
  120.         s = f.read()
  121.  
  122.     # process and output
  123.     with open(path + "\\" + test_folder + "\\" + folder_name + ".INP", "w") as f:
  124.         index = 0
  125.         lst = list(s)
  126.         try:
  127.             for item in s:
  128.                 index = lst.index(item, index)
  129.             f.write("0")
  130.         except ValueError:
  131.             f.write("1")
  132.  
  133. # 035
  134.  
  135. folder_name = "035XC0"
  136. path = ".\\..\\..\\NTT Code Web\\ntttest\\" + folder_name
  137.  
  138. for i in range(1, 11):
  139.     if (i != 10):
  140.         test_folder = "Test0" + str(i)
  141.     else:
  142.         test_folder = "Test10"
  143.  
  144.     def is_in_lst(x, y, len_x, len_y):
  145.         return ((0 <= x < len_x) and (0 <= y < len_y))
  146.    
  147.     # input
  148.     with open(path + "\\" + test_folder + "\\" + folder_name + ".INP", "r") as f:
  149.         lst = []
  150.         flatten = []
  151.         data = f.readlines()
  152.         for line in data:
  153.             lst.append(list(map(int, line.split())))
  154.             for item in line.split():
  155.                 flatten.append(int(item))
  156.  
  157.     # process and output
  158.     with open(path + "\\" + test_folder + "\\" + folder_name + ".INP", "w") as f:
  159.         flatten.sort()
  160.         x = 0
  161.         y = 0
  162.         direction = [[0, 1], [1, 0], [0, -1], [-1, 0]]
  163.         dir_index = 0
  164.         for item in flatten:
  165.             lst[x][y] = item
  166.             if (not is_in_list(x + direction[dir_index][0], y + direction[dir_index][1]), len(lst), len(lst[0]))
  167.                 dir_index += 1
  168.                 if (dir_index > 3):
  169.                     dir_index = 0
  170.             x += direction[dir_index][0]
  171.             y += direction[dir_index][1]
  172.         print_item = []
  173.         for line in lst:
  174.             print_item.append(" ".join(list(map(str, lst))))
  175.         f.writelines(print_item)
  176.  
  177. # 036
  178.  
  179. folder_name = "036ZZ"
  180. path = ".\\..\\..\\NTT Code Web\\ntttest\\" + folder_name
  181.  
  182. for i in range(1, 11):
  183.     if (i != 10):
  184.         test_folder = "Test0" + str(i)
  185.     else:
  186.         test_folder = "Test10"
  187.  
  188.     def is_in_lst(x, y, len_x, len_y):
  189.         return ((0 <= x < len_x) and (0 <= y < len_y))
  190.    
  191.     # input
  192.     with open(path + "\\" + test_folder + "\\" + folder_name + ".INP", "r") as f:
  193.         lst = []
  194.         flatten = []
  195.         data = f.readlines()
  196.         for line in data:
  197.             lst.append(list(map(int, line.split())))
  198.             for item in line.split():
  199.                 flatten.append(int(item))
  200.  
  201.     # process and output
  202.     with open(path + "\\" + test_folder + "\\" + folder_name + ".INP", "w") as f:
  203.         flatten.sort()
  204.         x = 0
  205.         y = 0
  206.         for item in flatten:
  207.             lst[x][y] = item
  208.             if (not is_in_list(x + direction[dir_index][0], y + direction[dir_index][1]), len(lst), len(lst[0]))
  209.                 dir_index += 1
  210.                 if (dir_index > 3):
  211.                     dir_index = 0
  212.             x += direction[dir_index][0]
  213.             y += direction[dir_index][1]
  214.         print_item = []
  215.         for line in lst:
  216.             print_item.append(" ".join(list(map(str, lst))))
  217.         f.writelines(print_item)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement