blob: dce0bca45456fd95aa8ca063b7004b9faa75d7cd (
plain)
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
|
#!/usr/bin/env perl
# Task 2: B After A
# Submitted by: Mohammad Sajid Anwar
#
# You are given a string, $str.
# Write a script to return true if there is at least one b, and no a appears after the first b.
#
# Example 1
# Input: $str = "aabb"
# Output: true
#
# Example 2
# Input: $str = "abab"
# Output: false
#
# Example 3
# Input: $str = "aaa"
# Output: false
#
# Example 4
# Input: $str = "bbb"
# Output: true
def out(str):
offset = str.find('b')
if offset >= 0 and str.find('a', offset) == -1:
res = "true"
else:
res = "false"
print("%s -> %s" %
( str, res )
)
if __name__ == "__main__":
str = "aabb"
out(str)
str = "abab"
out(str)
str = "aaa"
out(str)
str = "bbb"
out(str)
|