当前位置:网站首页>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
边栏推荐
- String ABC = new string ("ABC"), how many objects are created
- Analysis of penetration test learning and actual combat stage
- Beautified table style
- Zatan 0516
- Miscellaneous talk on May 14
- 7-8 7104 约瑟夫问题(PTA程序设计)
- SRC mining ideas and methods
- A piece of music composed by buzzer (Chengdu)
- 7-14 错误票据(PTA程序设计)
- PriorityQueue (large root heap / small root heap /topk problem)
猜你喜欢
这次,彻底搞清楚MySQL索引
甲、乙机之间采用方式 1 双向串行通信,具体要求如下: (1)甲机的 k1 按键可通过串行口控制乙机的 LEDI 点亮、LED2 灭,甲机的 k2 按键控制 乙机的 LED1
自定义RPC项目——常见问题及详解(注册中心)
SRC mining ideas and methods
[au cours de l'entrevue] - Comment expliquer le mécanisme de transmission fiable de TCP
Read only error handling
PriorityQueue (large root heap / small root heap /topk problem)
Yugu p1012 spelling +p1019 word Solitaire (string)
Attach the simplified sample database to the SQLSERVER database instance
Principles, advantages and disadvantages of two persistence mechanisms RDB and AOF of redis
随机推荐
7-15 h0161. 求最大公约数和最小公倍数(PTA程序设计)
Strengthen basic learning records
js判断对象是否是数组的几种方式
强化学习系列(一):基本原理和概念
FAQs and answers to the imitation Niuke technology blog project (II)
Nuxtjs quick start (nuxt2)
[three paradigms of database] you can understand it at a glance
Strengthen basic learning records
杂谈0516
强化学习基础记录
Record a penetration of the cat shed from outside to inside. Library operation extraction flag
渗透测试学习与实战阶段分析
[hand tearing code] single case mode and producer / consumer mode
[面试时]——我如何讲清楚TCP实现可靠传输的机制
自定义RPC项目——常见问题及详解(注册中心)
[the Nine Yang Manual] 2017 Fudan University Applied Statistics real problem + analysis
7-11 机工士姆斯塔迪奥(PTA程序设计)
Experiment 7 use of common classes (correction post)
7-5 走楼梯升级版(PTA程序设计)
[experiment index of educator database]