-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathAlternatingCharacters.py
More file actions
41 lines (30 loc) · 885 Bytes
/
Copy pathAlternatingCharacters.py
File metadata and controls
41 lines (30 loc) · 885 Bytes
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
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'alternatingCharacters' function below.
#
# The function is expected to return an INTEGER.
# The function accepts STRING s as parameter.
#
def alternatingCharacters(s):
# Write your code here
# Initialize a variable to count the number of deletions
deletions = 0
# Iterate through the string to count consecutive matching characters
for i in range(1, len(s)):
if s[i] == s[i - 1]:
# Increment the deletion count for consecutive matching characters
deletions += 1
return deletions
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
q = int(input().strip())
for q_itr in range(q):
s = input()
result = alternatingCharacters(s)
fptr.write(str(result) + '\n')
fptr.close()