#C7220. Interaction Counter
Interaction Counter
Interaction Counter
You are given a series of interactions that record when one individual greets or bids farewell to another. Each interaction is represented as a string in the format action name1 name2
, where action
is either greet
or farewell
. Your task is to count, for each individual who performs the action (i.e. appears as name1
), how many times they have greeted and how many times they have bid farewell. In the output, you should list each individual (sorted in alphabetical order) along with their respective counts in the format:
Name greet_count farewell_count
If there are no interactions, output an empty string.
inputFormat
The input is read from standard input (stdin). The first line contains an integer T, the number of interactions. The following T lines each contain a string representing an interaction in the format action name1 name2
. The action
is either greet
or farewell
.
outputFormat
Output to standard output (stdout) the count for each individual that performed an action. Each line should contain the individual's name, the number of times they greeted, and the number of times they bid farewell, separated by a space. The individuals should be listed in alphabetical order. If there are no interactions, output an empty string.
## sample4
greet Alice Bob
farewell Alice Bob
greet Bob Alice
farewell Bob Alice
Alice 1 1
Bob 1 1
</p>