当前位置:网站首页>Blue bridge code error ticket
Blue bridge code error ticket
2022-07-28 07:01:00 【White mouse zero】
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 .
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)
Each integer represents a ID Number .
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
for example :
User input :
2
5 6 8 11 9
10 12 9
Program output :
7 9
Another example is :
User input :
6
164 178 108 109 180 155 141 159 104 182 179 118 137 184 115 124 125 129 168 196
172 189 127 107 112 192 103 131 133 169 158
128 102 110 148 139 157 140 195 197
185 152 135 106 123 173 122 136 174 191 145 116 151 143 175 120 161 134 162 190
149 138 142 146 199 126 165 156 153 193 144 166 170 121 171 132 101 194 187 188
113 130 176 154 177 120 117 150 114 183 186 181 100 163 160 167 147 198 111 119
Program output :
105 120
Their thinking
Know from the question , This ID It was originally continuous and the punctuation point was not at the head and tail , that ID The broken sign must be [ head , tail ]. So I want to correspond this continuous number to the array a[idx] The subscript idx. Such as :1,2,4. It must be missing 3. How does the code judge ? We just have to let a[1]=1,a[2]=2,a[4]=4 after , After traversing the array once , Found a[3]=0( Here, assume that the array is initialized to 0), That means 3 The number is broken .
For how to find duplicate elements , Just be right at the beginning a[idx] When setting out , Let the corresponding vis[idx]++ To record the number of times this value appears .
Attach code
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int a[100005]={0}; // Put the number corresponding to the subscript , Such as :200 It must be on a[200] in
int vis[100005]={0}; // Record the number of occurrences of each number
int main()
{
int n;
cin>>n;
int min=100000; // Record the subscript of the minimum value
int max=-1; // Record the maximum subscript
getchar(); // Read out a carriage return
while(n>0)
{
string s;
getline(cin,s,'\n');// Read a line of string with spaces
int idx=0;
int len=s.length();
for(int i=0;i<len;i++)
{
if(s[i]!=' ') // Complete the reading of multi bit numbers
{
idx=idx*10+s[i]-'0';
}
if(s[i]==' '||i==len-1)
{
a[idx]=idx;
vis[idx]++;
if(min>idx)
min=idx;
if(max<idx)
max=idx;
idx=0;
}
}
n--;
}
for(int i=min;i<=max;i++)// Find the missing number
{
if(a[i]==0)
{
cout<<i<<" ";
break;
}
}
for(int i=min;i<=max;i++)// Look for duplicate numbers
{
if(vis[i]>1)
{
cout<<i<<endl;
break;
}
}
return 0;
}
边栏推荐
- Teach you three steps to complete the construction of the test monitoring system hand in hand
- Upload and download files from Ubuntu server
- Ubuntu18.04+centos7 configure redis master-slave [learning notes]
- It is recommended to wear air conduction earphones, which do not need to wear in ear
- Iptables firewall
- About gcc:multiple definition of
- Servlet
- [learning notes] linked list operation
- 技术分享 | 实战详解接口测试请求方式Get、post
- Hdu-5805-nanoape loves sequence (thinking questions)
猜你喜欢

Custom component -- pure data field & component life cycle

Esxi arm edition version 1.10 update

技术分享 | 服务端接口自动化测试, Requests 库的这些功能你了解吗?

搭建PHP7私有仓库

What is the most practical gift for Tanabata? A gift that will never go wrong is worth buying

Technology sharing | common proxy tools for interface testing

Firewall - iptables firewall (four tables and five links, firewall configuration method, detailed explanation of matching rules)

Which brand of air conduction earphones is good and highly praised

Technology sharing | how to simulate real use scenarios? Mock technology to help you

DHCP principle and configuration
随机推荐
手把手教你三步完成测试监控系统搭建
Ten thousand words summarize and realize the commonly used sorting and performance comparison
Custom component -- communication between parent and child components
Forward and backward slash notes
Shell script - "three swordsmen" awk command
Traversal binary tree
小甲鱼C(第六章数组1、2)
Shell script -- program conditional statements (conditional tests, if statements, case branch statements, echo usage, for loops, while loops)
Esxi arm edition version 1.10 update
修复故障扇区
HDU-5805-NanoApe Loves Sequence(思维题)
JS four operations are repackaged to solve the problem of precision loss
DNS正向解析实验
Technology sharing | how to simulate real use scenarios? Mock technology to help you
Shell script - regular expression
Esxi community network card driver updated again
My deployment notes
Ubuntu18.04+centos7 configure redis master-slave [learning notes]
单元测试框架Jest搭配TypeScript的安装与配置
What is the most practical gift for Tanabata? A gift that will never go wrong is worth buying