Blue Bridge Cup: Previous questions error Notes "Java Algorithm implementation"

Source: Internet
Author: User

Title Description

A certain secret unit issued a certain instrument, and to be fully recovered at the end of the year.

Each ticket has a unique ID number. All year round the ID number of the ticket is sequential, but the beginning of the ID is randomly selected.

Because the staff negligence, in the input ID number when an error occurred, resulting in an ID break number, and another ID number.

Your task is to programmatically find the ID of the broken number and the ID of the re-number.

It is assumed that the break number cannot occur in the maximum and the trumpet.

Input format

Each row of data length, is separated by a space of several (not more than 100) positive integer (not greater than 100000), please note that there may be extra space in the line and at the end of the line, your program needs to be able to handle these spaces.

Each integer represents an ID number.

Output format

Requires that the program output 1 lines, including two integer m n, separated by a space.

where m means the id,n is the number ID

Sample Input 1

3

5 6 8) 11 9

10 12 9

Sample Output 1

7 9

Sample Input 2

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

Sample Output 2

105 120

Import Java.util.arraylist;import java.util.collections;import Java.util.list;import Java.util.Scanner;public class Main {public static void main (String args[]) {Scanner cin = new Scanner (system.in); int n = cin.nextint (); String s[] = new String[n]; String ss[][] = new String[n][];cin.nextline (); for (int i = 0; i < n; i++) {S[i] = Cin.nextline (); Ss[i] = S[i].split (" ");} list<integer> list = new arraylist<integer> (), for (int i = 0, i < n; i++) for (int j = 0; J < Ss[i].lengt H J + +) {//System.out.println (Ss[i][j]); List.add (Integer.valueof (Ss[i][j]));} Collections.sort (list); int cw =-1, cf =-1, size = List.size (), A, b;for (int i = 0; i < size-1; i++) {A=list.get (i) if (A = = List.get (i + 1)) {CF = A;list.remove (i); break;}} for (int i = 0; i < size-1; i++) {a=list.get (i); if (A + 1! = List.get (i + 1)) {CW = a + 1;break;}} SYSTEM.OUT.PRINTLN (CW + "" + CF);}}


Blue Bridge Cup: Previous questions error Notes "Java Algorithm implementation"

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.