1065. Single dog (25) time limit of MS memory limit 65536 KB code length limit 8000 B procedure StandardAuthor Chen, Yue
"Single Dog" is a nickname for single people in Chinese. Ask you to find a single guest from a large party of tens of thousands of people in order to give special care.
Input format:
Enter the first line to give a positive integer n (<=50000), which is the logarithm of the known couple/partner, followed by n lines, each line gives a couple/partner-for convenience, each person corresponds to an ID number, 5 digits (from 00000 to 99999), separated by a space between the IDs After that, a positive integer m (<=10000) is given, which is the total number of participants in the party; the next line gives the ID of the M-guest, separated by a space. The topic guarantees that no one is bigamy or foot on two boats.
Output format:
The first line outputs the total number of guests on the list, followed by the second row to list the guests in ascending order by ID. IDs are separated by 1 spaces, and the lines must have no extra spaces.
Input Sample:
311111 2222233333 4444455555 66666755555 44444 10000 88888 22222 11111 23333
Sample output:
510000 23333 44444) 55555 88888
Python Source:
1Sum_couple =int (input ())2Couples = []3 forIinchRange (sum_couple):4Name =input ()5A =name.split () [0]6b = Name.split () [1]7c =( A, B), (b,a))8 Couples.extend (c)9dcouples=dict (Couples)Ten OneSum_guest =int (input ()) AGuest = [] -str =input () - forIinchRange (sum_guest): the Guest.append (Str.split () [i]) - -Sum_single =0 -Single = [] + forIinchRange (sum_guest): - ifGuest[i]inchDcouples: +x=Dcouples.get (Guest[i]) A ifXinchGuest: atSum_single-=1 - Else: - single.append (Guest[i]) - Else: - single.append (Guest[i]) - in Print(Len ( single)) - ifLen (single) >0: to Single.sort () + Print(single[0],end="') - ifLen (single) >1: the forIinchRange (1, Len ( single): * Print(" ", end="') $ Print(single[i],end="')
Results:
Test point 3 4 run timeout, unknown error
Pat B 1065. Single Dog by Python