CoolPairsEasy
SRM 799 · 2021-02-04 · by IH19980412
Problem Statement
There is a group of N people. Each person in the group has a first name and a last name: the names of person i are firstname[i] and lastname[i].
If A and B are two different people such that the last name of person A is the same as the first name of person B, the ordered pair (A, B) is called cool.
Please calculate and return the number of cool pairs for the given group of people.
Constraints
- N will be between 1 and 50, inclusive.
- firstname and lastname will contain exactly N elements each.
- Length of each element in firstname and lastname will have between 1 and 10, inclusive.
- Each element in firstname and lastname will only consist of lowercase English letters ('a'-'z').
{"elton", "tom", "john"}
{"john", "jones", "cena"}
Returns: 1
The pair (0, 2) is a cool pair because both person 0's last name and person 2's first name is "john". (Person 0 is called "elton john" and person 2 is called "john cena".)
{"james", "taylor"}
{"taylor", "james"}
Returns: 2
Note that the cool pairs are ordered pairs. In this example, (0, 1) is a cool pair and (1, 0) is a different cool pair.
{"jar"}
{"jar"}
Returns: 0
Remember that the two people in a cool pair must be distinct. Even though "jar jar" has the same first and last name, (0, 0) is not a cool pair.
{"lee", "stan", "ang", "marvin", "lee", "grace", "kelly", "jeremy"}
{"marvin", "lee", "lee", "gaye", "mack", "kelly", "clarkson", "clarkson"}
Returns: 6
{"major", "major", "major"}
{"major", "major", "major"}
Returns: 6
There are three distinct people in this example. Each of them is called "major major". There are six cool pairs: (0,1), (0,2), (1,0), (1,2), (2,0) and (2,1).
Submissions are judged against all 38 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class CoolPairsEasy with a public method int count(vector<string> firstname, vector<string> lastname) · 38 test cases · 2 s / 256 MB per case