当前位置:网站首页>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;
}
边栏推荐
- 技术分享 | 接口测试价值与体系
- Use powercli to create a custom esxi ISO image
- [learning notes] tool
- About gcc:multiple definition of
- Life cycle (process) of software testing
- 技术分享 | 如何模拟真实使用场景?mock 技术来帮你
- Teach you three steps to complete the construction of the test monitoring system hand in hand
- shell脚本——sort、uniq、tr、数组排序、cut、eval命令配置
- Icc2 analysis timing artifact analyze_ design_ violations
- Pku-2524-ubiquitous relations (parallel search template)
猜你喜欢

Applets: WSX scripts

File operation in C language

Centos7 deploy MySQL database server

iptables防火墙

Custom component -- pure data field & component life cycle

DNS forward resolution experiment

Esxi arm edition version 1.10 update

Custom components -- styles

Technology sharing | interface testing value and system

Technology sharing | do you know the functions of the server interface automated testing and requests library?
随机推荐
HDU-5805-NanoApe Loves Sequence(思维题)
Ubuntu18.04搭建redis集群【学习笔记】
[learning notes] drive
小甲鱼C(第六章数组1、2)
[learning notes] tool
Custom component -- pure data field & component life cycle
NFS shared storage service
DHCP原理与配置
技术分享 | 接口测试价值与体系
一、PXE概述和安装
MySQL主从
Hdu-2036-reform spring breeze blowing all over the ground (polygon area template)
Iptables firewall
Teach you three steps to complete the construction of the test monitoring system hand in hand
DNS正向解析实验
Esxi community network card driver updated in March 2022
CentOS7部署MySQL数据库服务器
Traversal binary tree
MOOC翁恺C语言第八周:指针与字符串:1.指针2.字符类型3.字符串4.字符串计算
Firewall - iptables firewall (four tables and five links, firewall configuration method, detailed explanation of matching rules)