-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemp1.py
More file actions
147 lines (125 loc) · 2.93 KB
/
temp1.py
File metadata and controls
147 lines (125 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#
# import itertools
#
# number_set = set()
#
#
# def add_number(dice, sequence, idx, number):
# if idx == len(sequence):
# number_set.add(number)
# return
#
# for n in dice[sequence[idx]]:
# add_number(dice, sequence, idx+1, number+str(n))
#
#
#
#
#
# # print([1] + [2])
#
#
# def solution(dice):
# answer = 0
#
# n = len(dice)
#
# for i in range(1, len(dice)+1):
# perm = list(itertools.permutations([x for x in range(n)], i))
# for p in perm:
# add_number(dice, p, 0, '')
#
# print(list(number_set))
# number_arr = list(set([int(x) for x in list(number_set)]))
#
# i = 0
# for idx, number in enumerate(number_arr):
# if idx > 0 and idx != number:
# return idx
#
#
# # print(list(itertools.permutations([0,1,2,3], 3)))
# c = solution([[1, 6, 2, 5, 3, 4], [9, 9, 1, 0, 7, 8]] )
# b = solution([[0, 1, 5, 3, 9, 2], [2, 1, 0, 4, 8, 7], [6, 3, 4, 7, 6, 5]])
# print(c)
# res = False
# def check_rule(string: str):
# global res
# if string == 'a':
# res = True
# return
#
# elif string.startswith('a'):
# # if string.endswith('b'):
# check_rule(string[1:])
#
# elif string.endswith('a'):
# # if string.startswith('b'):
# check_rule(string[:-1])
#
# elif string.startswith('b') and string.endswith('b'):
# check_rule(string[1:-1])
# else:
# return
# #
# #
def check_rule(string: str):
print(string)
# print()
a_idx = -1
for i in range(len(string)):
if string[i] == 'a':
a_idx = i
break
else:
return False
a_cnt = string.count('a')
print(a_cnt)
b_cnt = string.count('b')
string_arr = list(string)
while string_arr and a_cnt:
print(string_arr)
while string_arr[0] == 'a':
string_arr.pop(0)
print('asd')
a_cnt -= 1
while string_arr[-1] == 'a':
string_arr.pop()
a_cnt -= 1
i = 0
while i < a_cnt:
s, e = string_arr[0], string_arr[-1]
if s == 'b' and e == 'b':
string_arr.pop(0)
string_arr.pop()
else:
break
print()
if string_arr == ['arr']:
return True
else:
return False
#
#
# l_cnt, r_cnt = string[:a_idx+1].count('b'), string[a_idx+1:].count('b')
# print(a_idx)
# print(l_cnt, r_cnt)
# print(a_idx, len(string))
# for i in range(a_idx, len(string)):
# if string[i] == 'a' and l_cnt == r_cnt:
# return True
#
# if string[i] == 'b':
# l_cnt += 1
# r_cnt -= 1
#
# return False
def solution(a: list):
answer = []
for s in a:
answer.append(check_rule(s))
return answer
a = solution(["abab","bbaa","bababa","bbbabababbbaa", "baabaabab", "abbaa"])
print(a)
# arr = [1,2 , 3]
# print(arr[:-1])