본문 바로가기

BOJ/Python

이메일 만들기

 

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
import collections
company = input()
input = list(map(str,input().split(', ')));
 
res=[]
nameDic={}
for value in input:
    name = list(map(str, value.split()));
    last = name[len(name)-1].replace('-','')
    lastfirst = last.lower() + name[0][0].lower()
 
    cnt = int(nameDic.get(lastfirst,'0'))
    finalName=lastfirst
    if cnt > 0 :
        finalName = finalName + str(cnt+1)
 
    nameDic[lastfirst] = cnt+1
 
    tmp=[]
    tmp.append(finalName)
    tmp.append("@")
    tmp.append(company.lower())
    tmp.append(".com")
 
    res.append(''.join(tmp))
    #중복된 이메일은 뒤에 후속 숫자를 붙여준다.
 
for i in range(len(res)-1):
    print('{0}, '.format(res[i]), end='')
print(res[len(res)-1])

 

input

MIDASIT
John Doe, Peter Parker, Mary Jane Watson-Parker, James Doe, John Elvis Doe, Jane Doe, Penny Parker

output

doej@midasit.com, parkerp@midasit.com, watsonparkerm@midasit.com, doej2@midasit.com, doej3@midasit.com, doej4@midasit.com, parkerp2@midasit.com

'BOJ > Python' 카테고리의 다른 글