pythonchallenge level3
2009. 8. 19. 20:22
http://www.pythonchallenge.com/pc/def/equality.html
3번문제의 힌트는 아래와 같다. 소스를 살펴보면 level2 와 비슷하게 매우 긴 문자열을 볼 수 있다.
One small letter, surrounded by EXACTLY three big bodyguards on each of its sides
글자 그대로 해석하면 원하는 문자열은 XXXxXXX 형태일 것이다. Forum에 올라온 힌트는 정규식을 이용
하라고 나와있다. 가깝고도 먼 그대.. 정규표현식T_T
[A-Z]{3}[a-z][A-Z]{3} 요런식으로 만들어서 매칭시켜보니 무려 477개나 되는 문자가
발견되었다. 힌트를 곰곰히 읽어보니 Exactly 가 유독 대문자로 써 있다. 이말은 대문자의 갯수가 정확히
3개 여야 한다는 뜻이다. 따라서 xXXXxXXXx 요런 형태로 다시 찾아보았다.
import re str = """ .......................""" keyword = re.findall("[a-z][A-Z]{3}[a-z][A-Z]{3}[a-z]",str) i = 0 word = '' temp = '' length = len(keyword) while 1: temp = keyword[i] word += temp[4] i+=1 if i == length: break print word
위의 코드를 실행하면 최종 문자열로 linkedlist 가 찍힌다.
http://www.pythonchallenge.com/pc/def/linkedlist.html
'War game > pythonchallenge' 카테고리의 다른 글
pythonchallenge level11 (0) | 2009.10.22 |
---|---|
pythonchallenge level10 (0) | 2009.10.20 |
pythonchallenge level9 (0) | 2009.10.16 |
pythonchallenge level8 (0) | 2009.10.16 |
pythonchallenge level7 (0) | 2009.10.16 |
python challenge level6 (0) | 2009.09.21 |
python challenge level5 (0) | 2009.08.27 |
pythonchallenge level4 (0) | 2009.08.20 |
pythonchallenge level2 (0) | 2009.08.17 |
pythonchallenge level1 (0) | 2009.08.17 |