-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrightmostchar.py
36 lines (33 loc) · 1.01 KB
/
rightmostchar.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
"""RIGHTMOST CHAR
You are given a string 'S' and a character 't'. Print out the position of the rightmost occurrence of 't' (case matters)
in 'S' or -1 if there is none. The position to be printed out is zero based.
INPUT SAMPLE:
The first argument will ba a path to a filename, containing a string and a character, comma delimited, one per line.
Ignore all empty lines in the input file. E.g.
Hello World,r
Hello CodeEval,E
OUTPUT SAMPLE:
Print out the zero based position of the character 't' in string 'S', one per line. Do NOT print out empty lines between
your output.
8
10
"""
#import sys
#test_cases = open(sys.argv[1], 'r')
test_cases = {"Hello World,r", "Hello CodeEval,E", "Test Number,x","zzx z,z"}
for test in test_cases:
if test == "":
break
strings = test.split(",")
string = strings[0]
char = strings[1]
print string
print char
i = 0
location = -1
for letter in string:
if letter == char:
location = i
i += 1
print location
#test_cases.close()