当前位置:网站首页>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 9
Code (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
边栏推荐
- FAQs and answers to the imitation Niuke technology blog project (I)
- 【黑马早报】上海市监局回应钟薛高烧不化;麦趣尔承认两批次纯牛奶不合格;微信内测一个手机可注册俩号;度小满回应存款变理财产品...
- [the Nine Yang Manual] 2022 Fudan University Applied Statistics real problem + analysis
- [the Nine Yang Manual] 2019 Fudan University Applied Statistics real problem + analysis
- HackMyvm靶机系列(5)-warez
- About the parental delegation mechanism and the process of class loading
- Principles, advantages and disadvantages of two persistence mechanisms RDB and AOF of redis
- Analysis of penetration test learning and actual combat stage
- HackMyvm靶机系列(6)-videoclub
- 7-5 走楼梯升级版(PTA程序设计)
猜你喜欢
canvas基础2 - arc - 画弧线
[VMware abnormal problems] problem analysis & Solutions
C language Getting Started Guide
Intensive literature reading series (I): Courier routing and assignment for food delivery service using reinforcement learning
强化学习基础记录
.Xmind文件如何上传金山文档共享在线编辑?
2022泰迪杯数据挖掘挑战赛C题思路及赛后总结
4. Branch statements and loop statements
Difference and understanding between detected and non detected anomalies
Custom RPC project - frequently asked questions and explanations (Registration Center)
随机推荐
MySQL lock summary (comprehensive and concise + graphic explanation)
Wechat applet
7-1 output all primes between 2 and n (PTA programming)
TypeScript快速入门
杂谈0516
深度强化文献阅读系列(一):Courier routing and assignment for food delivery service using reinforcement learning
撲克牌遊戲程序——人機對抗
7-3 构造散列表(PTA程序设计)
强化学习基础记录
7-1 输出2到n之间的全部素数(PTA程序设计)
Force deduction 152 question multiplier maximum subarray
Mixlab unbounded community white paper officially released
[modern Chinese history] Chapter 6 test
It's never too late to start. The tramp transformation programmer has an annual salary of more than 700000 yuan
HackMyvm靶机系列(5)-warez
QT meta object qmetaobject indexofslot and other functions to obtain class methods attention
[hand tearing code] single case mode and producer / consumer mode
Implementation principle of automatic capacity expansion mechanism of ArrayList
实验四 数组
Experiment 8 exception handling