# Arup Guha
# 2/6/2012
# Replaces "bad words" in a message with alternative replacements.

def main():

    # Open the input file and read in all the contents.
    myfile = open('message.txt','r')
    str = myfile.read()

    # Splits the input into all of its separate pieces.
    msg = str.split()

    # Read in the number of bad words.
    numwords = int(input("How many bad words are there?"))

    # Store a dictionary with each bad word and its replacement.
    mydictionary = {}
    for i in range(numwords):
        bad = input("What is the next bad word?")
        good = input("What is its replacement?")
        mydictionary[bad] = good

    # Go through each word in the message.
    for i in range(len(msg)):

        # We found a bad word in the message. Replace it!
        if (msg[i] in mydictionary):
            print(mydictionary[msg[i]],end="")

        # This word is fine, print it out as is.
        else:
            print(msg[i],end="")
        print(" ",end="")

main()
    
