## CCC '14 S2 - Assigning Partners

View as PDF

Points: 5
Time limit: 2.0s
Memory limit: 64M

Problem type
##### Canadian Computing Competition: 2014 Stage 1, Junior #5, Senior #2

The CEMC is organizing a workshop with an activity involving pairs of students. They decided to assign partners ahead of time. You need to determine if they did this consistently. That is, whenever A is a partner of B, then B is also a partner of A, and no one is a partner of themselves.

#### Input Specification

The input consists of three lines. The first line consists of an integer , which is the number of students in the class. The second line contains the first names of the students separated by single spaces. (Names contain only uppercase or lowercase letters, and no two students have the same first name). The third line contains the same names in some order, separated by single spaces.

The positions of the names in the last two lines indicate the assignment of partners: the th name on the second line is the assigned partner of the th name on the third line.

#### Output Specification

The output will be good if the two lists of names are arranged consistently, and bad if the arrangement of partners is not consistent.

#### Sample Input 1

4
John Grace Alan Ada

#### Output for Sample Input 1

good

#### Explanation for Output for Sample Input 1

Ada and John are partners, and Alan and Grace are partners. This arrangement is consistent.

#### Sample Input 2

7
Rich Graeme Michelle Sandy Vlado Ron Jacob
Ron Vlado Sandy Michelle Rich Graeme Jacob

#### Output for Sample Input 2

bad

#### Explanation for Output for Sample Input 2

Graeme is partnered with Vlado, but Vlado is partnered with Rich. This is not consistent. It is also inconsistent because Jacob is partnered with himself.

• commented on Feb. 4, 2022, 10:00 p.m. edit 4

can anyone explain to me why I have gotten test case #10 wrong?, I tried all the test cases in the comment sections, however, my code prints correctly for those

edit: nvm, for anyone else who is also getting test case #10 wrong try

6
A B C D E F
F C B D E A

• commented on Feb. 4, 2022, 10:10 p.m.

Try this test case:

4
a b c d
d b c a
• commented on Jan. 25, 2022, 11:15 p.m.

Anyone know why I cant get test #10

• commented on Jan. 26, 2022, 8:06 a.m.

The reason is because you only look at the first half of the list of names, which is understandable but can fail to test cases like this:

6
a b c d e f
d c b a f g

Your code prints good

• commented on Jan. 30, 2022, 12:35 a.m.

Thanks brah

• commented on Dec. 27, 2021, 6:42 p.m.

Does anyone know what test case 6 is asking?

• commented on Dec. 28, 2021, 10:01 a.m.

Asking what the test case is asking doesn't mean anything, as only the question setters know.

Try this test case:

3
a b c
c a b

• commented on July 4, 2020, 3:37 p.m.

This comment is hidden due to too much negative feedback. Show it anyway.

• commented on July 4, 2020, 5:19 p.m.

That's not what the problem is asking you to do. I'm surprised you got that many test cases right. You're supposed to be checking if each of the two names are being matched consistently, and the two partners are always partnered up with each other.

• commented on July 4, 2020, 5:15 p.m. edit 4

Your solution is incorrect: you should try thinking of another solution to verify the partners are valid. If you're still stumped, try looking at the test cases you get wrong (namely, 2a, 2b, and 5a).

• commented on Jan. 6, 2019, 8:17 p.m. edited

Many ways to do it.