U E D R , A S I H C RSS

Classify By Anagram/Ju Ne

~cpp 
import sys

def Anagram(inFile,outFile):
    anagrams={}
    for eachWord in inFile:
        eachWord=eachWord.strip()
        key=list(eachWord);key.sort();key=''.join(key)
        anagrams.setdefault(key,[]).append(eachWord)
    for eachAnagram in anagrams.itervalues():
        print >> outFile, ' '.join(eachAnagram)

if __name__=='__main__':
    Anagram(sys.stdin,sys.stdout)

P4 1.8Ghz 512MB Win XP Python 2.2.1에서 17만 단어로 실행하면 4초. 프로세스 메모리 점유 약 31MB. 만약 psyco로 bind를 해주면(if문 위에 ~cpp import psyco;psyco.bind(Aangram)을 추가) 3.4초.
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:22:53
Processing time 0.0089 sec