Blue Bridge Cup Selected Questions Series - Error Bills (2013 Provincial)

Topic description

A secret-related unit has issued some kind of bills, which are to be recovered at the end of the year.

Each ticket has a unique ID number. The ID numbers for all bills throughout the year are consecutive, but the starting numbers of the IDs are randomly selected.

Due to the negligence of the staff, an error occurred when entering the ID number, resulting in a broken ID for one ID and a duplicate ID for another.

Your task is to programmatically find out the ID of the break number and the ID of the double number.

It is assumed that break numbers cannot occur at the largest and smallest numbers.

enter description

The program is required to first input an integer N (N<100) to represent the number of data lines that follow.

Then read in N lines of data.

The length of each line of data varies, and is a number of (not more than 100) positive integers (not more than 10 5 ) separated by spaces.

output description

The program is required to output 1 line containing two integers m, n, separated by spaces.

Among them, m represents the break ID, and n represents the repeat ID.

Input and output example

Example

enter

2
5 6 8 11 9
10 12 9

output

7 9

Operational restrictions

Maximum running time: 1s
Maximum running memory: 64M

detailed answer

n = int(input())
listsum = []
for w in range(n):
    listsum.append(list(map(str,input().split()) ))
wzy = listsum[0]
for y in range(1,n):
    wzy = listsum[y]+wzy
res = [int(i) for i in wzy]
wzypaixu = sorted(res)
wzyquchong = set(wzypaixu)
numb = wzypaixu[0]
for i in range(len(wzyquchong)):
    counter = wzypaixu.count(numb)
    if counter >1:
        a=numb
    if numb in wzyquchong:
        numb +=1
    else:
        b = numb
        numb +=1
print(b,a)

This code may look a lot, and the name is specially used to make it easier for everyone to understand. For example, to deduplicate the list, I will use listname+quchong to name it, such as

wzyquchong = set(wzypaixu)

Sorted lists are similar.
This code may be more complicated to write, and it feels like the most stupid method. If you have a good problem-solving method, please comment and chat privately.

Guess you like

Origin blog.csdn.net/m0_51951121/article/details/122642139