-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathP16_CarNames.py
59 lines (57 loc) · 1.65 KB
/
P16_CarNames.py
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
# Brian built his own car and was confused about what name he should keep for it. He asked Roman for help. Roman being his
# good friend, suggested a lot of names.
# Brian only liked names that:
# - Consisted of exactly three distinct characters, say C1, C2 and C3
# - Satisfied the criteria that the string was of the form - C1n C2n C3n : This means, first C1 occurs n times, then C2
# occurs n times and then C3 occurs n times. For example, xyz, ccaarr, mmmiiiaaa satisfy the criteria, but xyzw, aabbbcccc
# don't.
# Given N names suggested by Roman, print "OK" if Brian likes the name and "Not OK" if he doesn't.
#
# Input:
# First line contains a single positive integer N - the number of names.
# N lines follow - each line contains a name.
#
# Output:
# For each name, Print "OK" if the name satisfies the criteria, else print "Not OK", on a new line.
#
# Constraints:
# 1 ≤ N ≤ 100
# 1 ≤ Length of names ≤ 500
# Names contain only lowercase English alphabets
#
# SAMPLE INPUT
# 2
# bbbrrriii
# brian
# SAMPLE OUTPUT
# OK
# Not OK
alphabets = 'abcdefghijklmnopqrstuvwxyz'
testCases = int(input())
for _ in range(testCases):
string = input()
count1 = 0
count2 = 0
count3 = 0
i = 0
end = 0
c1 = 0
while string[i] == string[c1]:
count1 += 1
i += 1
c2 = i
while string[i] == string[c2]:
count2 += 1
i += 1
c3 = i
try:
while string[i] == string[c3]:
count3 += 1
i += 1
except:
end = 1
pass
if (count2 == count3 and end == 1):
print('OK')
else:
print('Not OK')