当前位置:网站首页>7-14 error ticket (PTA program design)
7-14 error ticket (PTA program design)
2022-07-06 13:56:00 【Programming Lindaiyu】
Some secret related unit has issued some kind of bill , And take it back at the end of the year .
Each note has a unique ID Number . Of all bills throughout the year ID The number is continuous , but ID The start number of is randomly selected .
Because of the negligence of the staff , In the input ID There was a mistake on the , Created something ID Break the number , Another one ID Duplicate number .
Your task is to program , Find the broken one ID And the heavy one ID.
Suppose that the interrupt can't happen on the largest and the smallest .
Input format :
Ask the program to enter an integer first N(N< 100) Indicates the number of subsequent data lines .
Then read in N Row data .
The data length of each row is not equal , It's a number of... Separated by spaces ( No more than 100 individual ) Positive integer ( No more than 100000), Please note that there may be extra spaces inside and at the end of the line , Your program needs to be able to handle these spaces .
Each integer represents a ID Number .
Output format :
Request program output 1 That's ok , Two integers m n, Separate... With spaces .
among ,m It's a break ID,n It's a double sign ID
sample input :
Here's a set of inputs . for example :
2
5 6 8 11 9
10 12 9
sample output :
Here is the corresponding output . for example :
7 9Code (Python):
list1=[] # Auxiliary input n Line error ticket
list2=[] # Deposit the wrong bill
n=int(input()) #n Indicates the number of subsequent data lines
for i in range(n): # Deposit the wrong note , loop n Times represents the number of data rows
list1.clear() # Before each cycle , take list1 Empty data in
list1=list(map(int,input().split())) # Enter each line of data to list1
for i in range(len(list1)): # take list1 Each data in is stored in list2 in
list2.append(list1[i])
xiao=min(list2) # Take the minimum value in the wrong ticket
da=max(list2) # Take the maximum value in the wrong ticket
for i in range(xiao,da+1): # Look for a hyphen
if i not in list2: # Judge whether each number between the minimum value and the maximum value is list2 in
duan=i # If not , Then the number is a hyphen
print(duan,end=' ') # Output hyphen , End with a space
for i in list2: # Duplicate number found
if list2.count(i)==2: # use Python Built in functions in count, Statistics list2 The number of occurrences of each element in , If it happens twice , Then the element is a duplicate sign
print(i,end='') # Output duplicate number
break # Because the duplicate number has been found , So exit the loop When I first saw this problem, I thought it was very difficult , Because it looks complicated . But I still tried it , It's not difficult to find , Is the most basic mathematical knowledge , There is no hard Algorithm . therefore , When you come across a seemingly difficult problem , And don't give up , Try to do it , To analyze , Maybe it's not very difficult , Or maybe it's really a little difficult , But how do you know if you will not try , What if you make it yourself ? So don't set limits on yourself , Try boldly , To challenge .
The above program gives more detailed comments , For novice Xiaobai's reference . The idea of program design or code implementation is not optimal , You are welcome to correct your mistakes or give better ideas .
I am a rookie who wants to be Kunpeng , Everyone's encouragement is my driving force , Welcome to like collection comments
边栏推荐
- String ABC = new string ("ABC"), how many objects are created
- Wechat applet
- Beautified table style
- 强化学习基础记录
- Read only error handling
- PriorityQueue (large root heap / small root heap /topk problem)
- MySQL事务及实现原理全面总结,再也不用担心面试
- 强化学习系列(一):基本原理和概念
- . Net6: develop modern 3D industrial software based on WPF (2)
- 实验六 继承和多态
猜你喜欢

HackMyvm靶机系列(5)-warez
![[hand tearing code] single case mode and producer / consumer mode](/img/b3/243843baaf0d16edeab09142b4ac09.png)
[hand tearing code] single case mode and producer / consumer mode

仿牛客技术博客项目常见问题及解答(一)

Mixlab unbounded community white paper officially released
![[VMware abnormal problems] problem analysis & Solutions](/img/64/f44864da600b61a1a646a5865a2083.jpg)
[VMware abnormal problems] problem analysis & Solutions
![[面试时]——我如何讲清楚TCP实现可靠传输的机制](/img/d6/109042b77de2f3cfbf866b24e89a45.png)
[面试时]——我如何讲清楚TCP实现可靠传输的机制

强化学习基础记录

【黑马早报】上海市监局回应钟薛高烧不化;麦趣尔承认两批次纯牛奶不合格;微信内测一个手机可注册俩号;度小满回应存款变理财产品...

撲克牌遊戲程序——人機對抗

HackMyvm靶机系列(6)-videoclub
随机推荐
[during the interview] - how can I explain the mechanism of TCP to achieve reliable transmission
Yugu p1012 spelling +p1019 word Solitaire (string)
Experiment 9 input and output stream (excerpt)
The difference between cookies and sessions
3. Input and output functions (printf, scanf, getchar and putchar)
Canvas foundation 1 - draw a straight line (easy to understand)
1. First knowledge of C language (1)
Programme de jeu de cartes - confrontation homme - machine
String ABC = new string ("ABC"), how many objects are created
强化学习基础记录
QT meta object qmetaobject indexofslot and other functions to obtain class methods attention
canvas基础1 - 画直线(通俗易懂)
[the Nine Yang Manual] 2020 Fudan University Applied Statistics real problem + analysis
[MySQL table structure and integrity constraint modification (Alter)]
Poker game program - man machine confrontation
7-15 h0161. 求最大公约数和最小公倍数(PTA程序设计)
Experiment 8 exception handling
7-1 output all primes between 2 and n (PTA programming)
7-14 错误票据(PTA程序设计)
仿牛客技术博客项目常见问题及解答(三)