Last active
April 7, 2018 10:48
-
-
Save maelfosso/139844d7b28e2ee07b4afbf03efa4598 to your computer and use it in GitHub Desktop.
Chef decided to find the connections with all of his friends in an unnamed social network. He calls a user of the social network his friend if there is a common substring of the string "chef" and the nickname of that user with length ≥ 2. Given a list of users of the social network, compute the number of Chef's friends.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ``` | |
| import sys | |
| chef_sub_str = [ | |
| 'ch', 'che', 'chef', | |
| 'he', 'hef', | |
| 'ef' | |
| ] | |
| # Read the number of potential friends | |
| N = int(input()) | |
| if not(1 <= N and N <= 5000): | |
| print("Error - ", N) | |
| # Read each friend and put it into the array | |
| users = [] | |
| for i in range(N): | |
| u = str(input()) | |
| if not(3 <= len(u) and len(u) <= 20) : | |
| sys.exit("Erreur ", u) | |
| users.append(u) | |
| # Find connections | |
| result = 0 | |
| for u in users: | |
| if any(s in u for s in chef_sub_str): | |
| result = result + 1 | |
| # Print results | |
| print(result) | |
| ``` |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Success !!