Skip to content

Instantly share code, notes, and snippets.

@PierraKimathi-zz
Created February 10, 2019 19:52
Show Gist options
  • Save PierraKimathi-zz/3699bc9a50c1f76f4769c7b62f581b1d to your computer and use it in GitHub Desktop.
Save PierraKimathi-zz/3699bc9a50c1f76f4769c7b62f581b1d to your computer and use it in GitHub Desktop.
Munene Word Search
"""
Munene is extremely disappointed to find out that no one in the office knows his first name. Even his close mates call him only by his last name. Frustrated, he decides to make his fellow workmates know his first name by forcing them to solve this question.
You are given a long string as input in each testcase, containing any ASCII character. Your task is to find out the number of times SUVO and SUVOJIT appears in it.
Note: This problem CAN BE SOLVED IN Java, Python or PHP.
Input Format
The first line contains the number of testcases, T. Next, T lines follow each containing a long string S.
Output Format
For each long string S, display the no. of times SUVO and SUVOJIT appears in it."""
#Created using Python 3
input_length = int(input()) #This determines the number of lines containing long strings test cases.
#This are the string examples we will search in the long string test cases.
SEARCH_STRING_ONE = 'SUVO'
SEARCH_STRING_TWO = 'SUVOJIT'
while(input_length): #Loop to search for our test strings in the long string test cases.
input_length -= 1 #This determine the next long string case to search.
try:
#Capture the long string test case input.
words = input()
#The count() function will determine the number of times our search strings appear.
first = words.count(SEARCH_STRING_ONE)
second = words.count(SEARCH_STRING_TWO)
#This ensures words from the long test string are not counted twice in a single count.
first = first-second
first = str(first)+','
#Print your results.
print('SUVO =' ,first, 'SUVOJIT =',second)
except EOFError as error:
print ("No more long string input.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment