Skip to content

Commit 0238e74

Browse files
authored
Create razo.py
1 parent 3616cc0 commit 0238e74

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

Misc/razo.py

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""
2+
Code Chef problem
3+
Razo is a brilliant student in maths. One day his mother asked him about his rank in his class, but he didn't like the school's system
4+
of ranking so he refused to give the answer. Help Razo's mother to find the rank of his son. School has strange way of ranking the
5+
students. They rank students according to lexicographical order of their surnames.
6+
Class contains N+1 students including Razo.
7+
Some characters in student's surnames are missing and missing part is replaced with ∗ in the surname. Razo's surname will never
8+
contains ∗ in it. You have to tell all possible rank of Razo, when you arrange N surnames with Razo's surname lexicographically.
9+
Input:
10+
The first line contains integer N (1≤N≤100000), denoting the number of surnames to process.The following N+1 lines contains student's
11+
surname, one surname per line.The N+1 th line contains Razo's surname. Each string contains only lowercase Latin letters, its length is
12+
between 1 and 100, inclusive.
13+
Output:
14+
Print all possible rank of Razo in a single line, separated by spaces.
15+
Sample Input 1:
16+
2
17+
hacker
18+
code
19+
rank
20+
Sample Output 1 :
21+
3
22+
Sample Input 2:
23+
2
24+
**cker
25+
*o*e
26+
rank
27+
Sample Output 2:
28+
1 2 3
29+
"""
30+
31+
# cook your dish here
32+
def isLexoLesser(name1,name2):
33+
if name1 == name2 or name1 == "" or name2 == "":
34+
return True
35+
elif name2[0] == "*":
36+
return True #if name1[0] != "a" else isLexoLesser(name1[1:],name2[1:])
37+
elif ord(name1[0]) < ord(name2[0]):
38+
return True
39+
elif ord(name1[0]) > ord(name2[0]):
40+
return False
41+
else:
42+
return isLexoLesser(name1[1:],name2[1:])
43+
44+
numStudents = int(input())
45+
studentArray = []
46+
for i in range(numStudents):
47+
studentArray.append(input())
48+
#studentArray.sort()
49+
razoName = input()
50+
rank = 1
51+
for name in studentArray:
52+
if not isLexoLesser(razoName,name):
53+
rank += 1
54+
#print(studentArray)
55+
print(" ".join(map(str,range(rank,numStudents+2))))

0 commit comments

Comments
 (0)