46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
|
|
"""
|
||
|
|
name: Nicholas Tamassia
|
||
|
|
Honor Code and Acknowledgments:
|
||
|
|
This work complies with the JMU Honor Code.
|
||
|
|
Comments here on your code and submission.
|
||
|
|
"""
|
||
|
|
|
||
|
|
import sys
|
||
|
|
|
||
|
|
|
||
|
|
# All modules for CS 412 must include a main method that allows it
|
||
|
|
# to imported and invoked from other python scripts
|
||
|
|
def main():
|
||
|
|
|
||
|
|
sounds: list[str] = sys.stdin.readline().strip().split(" ")
|
||
|
|
num_animals: int = int(sys.stdin.readline().strip())
|
||
|
|
|
||
|
|
fox_sounds: list[str] = []
|
||
|
|
animals_ecountered: list[str] = []
|
||
|
|
|
||
|
|
animal_sounds: list[tuple[str, str]] = list(
|
||
|
|
map(
|
||
|
|
lambda line: line.strip().split(" goes "),
|
||
|
|
sys.stdin.readlines()[:num_animals],
|
||
|
|
)
|
||
|
|
)
|
||
|
|
|
||
|
|
for sound in sounds:
|
||
|
|
animal_found = False
|
||
|
|
for animal, animal_sound in animal_sounds:
|
||
|
|
if sound == animal_sound:
|
||
|
|
animal_found = True
|
||
|
|
if animal not in animals_ecountered:
|
||
|
|
animals_ecountered.append(animal)
|
||
|
|
break
|
||
|
|
|
||
|
|
if not animal_found:
|
||
|
|
fox_sounds.append(sound)
|
||
|
|
|
||
|
|
print("what the fox says: " + " ".join(fox_sounds))
|
||
|
|
print("also heard: " + " ".join(animals_ecountered))
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|