Pat B 1065. Single Dog by Python

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.