1503150049-blue bridge cup-Incorrect tickets for previous questions, answers to previous questions of Blue Bridge cup

Source: Internet
Author: User

1503150049-blue bridge cup-Incorrect tickets for previous questions, answers to previous questions of Blue Bridge cup
Previous exam errors ticket time limit: 1.0 s memory limit: 256.0 MBProblem description

A confidential organization issues a certain ticket and must withdraw it all at the end of the year.

Each ticket has a unique ID number. The IDS of all bills for the year are consecutive, but the IDS start to be randomly selected.

Due to the negligence of the staff, an error occurred when entering the ID number, resulting in an ID disconnection and another ID duplication.

Your task is to find the ID of the break number and the ID of the duplicate number through programming.

Assume that the part number cannot be generated in the largest and smallest part number.

Input Format

The program must first input an integer N (N <100) to indicate the number of subsequent data rows.

Then, N rows of data are read.

The Data Length of each row is unequal. It is a number of positive integers separated by spaces (not greater than 100) (not greater than 100000). Please note that there may be extra spaces in the row and at the end of the row, your program needs to be able to process these spaces.

Each integer represents an ID.

Output Format

The program must output one line, which contains two integers, m n, separated by spaces.

Where, m indicates the ID of the disconnected number, and n indicates the ID of the duplicate number.

Example input 12
5 6 8 11 9
10 12 9 sample output 17 9 sample input 26
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
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 sample output 2105 120 solutions this question is very simple at first glance, store the data in an array and sort it in sequence, because the data is continuous, and then find the missing number and repeated number output in the middle. However, this question is really about string input. Because n rows of data are input, but each row does not contain data, some may be a line of space, so you need to judge more. Enter a string with spaces and use the gets (s) Code # include <stdio. h>
# Include <string. h>
# Include <algorithm>
Using namespace std;
Char s [12000000];
Int num [110];
Int main ()
{
Int n;
Int len, sum;
Int now;
Int I, j, k;
Int a, B;
While (scanf ("% d", & n )! = EOF)
{
Getchar ();
Sum = 0;
For (I = 0; I <n; I ++)
{
Gets (s); // use gets to enter Spaces
// You can input and judge the edge.
Len = strlen (s );
For (j = 0; j <len; j ++)
{
If (s [j]> = '0' & s [j] <= '9 ')
{
Now = 0;
For (k = j; s [k]! = ''& K <len; k ++)
// Note that k must be within the string length.
{
Now = now * 10 + s [k]-'0 ';
}
Num [sum ++] = now;
J = k;
}
}
}
Sort (num, num + sum );
For (I = 0; I <sum; I ++)
{
If (num [I] = num [I + 1]-2)
A = num [I] + 1;
If (num [I] = num [I + 1])
B = num [I];
}
Printf ("% d \ n", a, B );
}
Return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.