Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 029
- import string
- folder_name = "029XC1"
- path = ".\\..\\..\\NTT Code Web\\ntttest\\" + folder_name
- for i in range(1, 11):
- if (i != 10):
- test_folder = "Test0" + str(i)
- else:
- test_folder = "Test10"
- # input
- with open(path + "\\" + test_folder + "\\" + folder_name + ".INP", "r") as f:
- s = f.read()
- # process and output
- with open(path + "\\" + test_folder + "\\" + folder_name + ".INP", "w") as f:
- for item in s:
- if item not in string.ascii_letters:
- s = s.replace(item, "")
- f.write(" ".join(item.capitalize() for item in s.strip().split()))
- # 030
- import string
- folder_name = "030XC2"
- path = ".\\..\\..\\NTT Code Web\\ntttest\\" + folder_name
- for i in range(1, 11):
- if (i != 10):
- test_folder = "Test0" + str(i)
- else:
- test_folder = "Test10"
- # input
- with open(path + "\\" + test_folder + "\\" + folder_name + ".INP", "r") as f:
- s = f.read()
- # process and output
- with open(path + "\\" + test_folder + "\\" + folder_name + ".INP", "w") as f:
- for item in s:
- if item not in string.ascii_letters:
- s = s.replace(item, "")
- lst = item.capitalize() for item in s.strip().split())
- lst.sort()
- f.write(" ". join(lst))
- # 031
- folder_name = "031DX1"
- path = ".\\..\\..\\NTT Code Web\\ntttest\\" + folder_name
- def is_palindrome(s):
- return s == s[::-1]
- for i in range(1, 11):
- if (i != 10):
- test_folder = "Test0" + str(i)
- else:
- test_folder = "Test10"
- # input
- with open(path + "\\" + test_folder + "\\" + folder_name + ".INP", "r") as f:
- s = f.read()
- # process and output
- with open(path + "\\" + test_folder + "\\" + folder_name + ".INP", "w") as f:
- index = 0
- while (not is_palindrome(s)):
- s += s[index]
- index += 1
- f.write(s)
- #032
- import sys
- folder_name = "032DX2"
- path = ".\\..\\..\\NTT Code Web\\ntttest\\" + folder_name
- def is_palindrome(s):
- return s == s[::-1]
- for i in range(1, 11):
- if (i != 10):
- test_folder = "Test0" + str(i)
- else:
- test_folder = "Test10"
- # input
- with open(path + "\\" + test_folder + "\\" + folder_name + ".INP", "r") as f:
- s = f.read()
- # process and output
- with open(path + "\\" + test_folder + "\\" + folder_name + ".INP", "w") as f:
- max_value = -sys.maxsize()
- result = ""
- for i in range(0, len(s)):
- for j in range(0, len(s)):
- substring = s[i:j]
- if (substring != "") and (is_palindrome(substring)):
- if (len(substring) > max_value):
- max_value = len(substring)
- result = substring
- f.write(substring)
- # 034
- import sys
- folder_name = "034XC"
- path = ".\\..\\..\\NTT Code Web\\ntttest\\" + folder_name
- for i in range(1, 11):
- if (i != 10):
- test_folder = "Test0" + str(i)
- else:
- test_folder = "Test10"
- # input
- with open(path + "\\" + test_folder + "\\" + folder_name + ".INP", "r") as f:
- s = f.read()
- # process and output
- with open(path + "\\" + test_folder + "\\" + folder_name + ".INP", "w") as f:
- index = 0
- lst = list(s)
- try:
- for item in s:
- index = lst.index(item, index)
- f.write("0")
- except ValueError:
- f.write("1")
- # 035
- folder_name = "035XC0"
- path = ".\\..\\..\\NTT Code Web\\ntttest\\" + folder_name
- for i in range(1, 11):
- if (i != 10):
- test_folder = "Test0" + str(i)
- else:
- test_folder = "Test10"
- def is_in_lst(x, y, len_x, len_y):
- return ((0 <= x < len_x) and (0 <= y < len_y))
- # input
- with open(path + "\\" + test_folder + "\\" + folder_name + ".INP", "r") as f:
- lst = []
- flatten = []
- data = f.readlines()
- for line in data:
- lst.append(list(map(int, line.split())))
- for item in line.split():
- flatten.append(int(item))
- # process and output
- with open(path + "\\" + test_folder + "\\" + folder_name + ".INP", "w") as f:
- flatten.sort()
- x = 0
- y = 0
- direction = [[0, 1], [1, 0], [0, -1], [-1, 0]]
- dir_index = 0
- for item in flatten:
- lst[x][y] = item
- if (not is_in_list(x + direction[dir_index][0], y + direction[dir_index][1]), len(lst), len(lst[0]))
- dir_index += 1
- if (dir_index > 3):
- dir_index = 0
- x += direction[dir_index][0]
- y += direction[dir_index][1]
- print_item = []
- for line in lst:
- print_item.append(" ".join(list(map(str, lst))))
- f.writelines(print_item)
- # 036
- folder_name = "036ZZ"
- path = ".\\..\\..\\NTT Code Web\\ntttest\\" + folder_name
- for i in range(1, 11):
- if (i != 10):
- test_folder = "Test0" + str(i)
- else:
- test_folder = "Test10"
- def is_in_lst(x, y, len_x, len_y):
- return ((0 <= x < len_x) and (0 <= y < len_y))
- # input
- with open(path + "\\" + test_folder + "\\" + folder_name + ".INP", "r") as f:
- lst = []
- flatten = []
- data = f.readlines()
- for line in data:
- lst.append(list(map(int, line.split())))
- for item in line.split():
- flatten.append(int(item))
- # process and output
- with open(path + "\\" + test_folder + "\\" + folder_name + ".INP", "w") as f:
- flatten.sort()
- x = 0
- y = 0
- for item in flatten:
- lst[x][y] = item
- if (not is_in_list(x + direction[dir_index][0], y + direction[dir_index][1]), len(lst), len(lst[0]))
- dir_index += 1
- if (dir_index > 3):
- dir_index = 0
- x += direction[dir_index][0]
- y += direction[dir_index][1]
- print_item = []
- for line in lst:
- print_item.append(" ".join(list(map(str, lst))))
- f.writelines(print_item)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement