Skip to content

Instantly share code, notes, and snippets.

@maelfosso
Last active April 7, 2018 10:48
Show Gist options
  • Select an option

  • Save maelfosso/139844d7b28e2ee07b4afbf03efa4598 to your computer and use it in GitHub Desktop.

Select an option

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.
```
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)
```
@maelfosso
Copy link
Author

Success !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment