Fourth session Waterloo Cup B group java--error bill

Source: Internet
Author: User
/*
Title: Error Ticket
A secret-related unit has issued some kind of bill and has to withdraw it at the end of the year.
Each ticket has a unique ID number. The ID number of all bills is continuous throughout the year, but the starting digit of the ID is randomly selected.
Because the staff negligence, in the entry ID number of a mistake occurred, resulting in a certain ID number, another ID number.
Your task is to programmatically identify the ID of the broken number and the ID of the heavy number.
Suppose the broken number cannot occur in the largest and most small.
Requires that the program first enter an integer N (n<100) to represent the number of subsequent rows of data.
Then read n rows of data.
The length of each row of data, is separated by a number of (no more than 100) positive integers (not greater than 100000)
Each integer represents an ID number.


Requires that the program output 1 lines, with two integers m n, separated by a space.
where m represents the Id,n ID of the number of broken numbers


For example:
User input:
2
5 6 8 11 9
10 12 9


The program output:
7 9


Again for example:
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


The program output:
105 120

Resource conventions:
Peak memory consumption (including virtual machines) < 64M
CPU Consumption < 2000ms


Please output strictly according to the requirements, do not superfluous print similar: "Please enter ..." Superfluous content.
All the code is placed in the same source file, after debugging, the copy is submitted to the source.
Note: Do not use package statements. Do not use jdk1.6 and the above version of the features.
Note: The name of the main class must be: main, otherwise it will be handled in an invalid code.
*/


Import java.util.*;
public class Cuowupiaoju {
public static void Main (string[] args)
{
Scanner S1 = new Scanner (system.in);

System.out.println ("Please enter line number");
int n = s1.nextint ();
int num[] = new int[10000];
int count = 0; Number of data
int dh_id = 0; ID of broken number
int ch_id = 0; ID of the heavy number

To load data into an array
System.out.println ("Please enter data");
for (int i = 0; i<n; i++)
{
Scanner s2 = new Scanner (system.in);
Scanner s3 = new Scanner (S2.nextline ());

while (S3.hasnext ())
{
num[count++] = S3.nextint ();
}
}

Sample Broken Number
for (int i=0; i<count; i++)
{
if (num[i]+1!= num[i+1])
{
dh_id = Num[i];
Break
}
}

Sample Duplicate
for (int i=0; i<count; i++)
{
for (int j=count-1; j>i; j--)
{
if (num[i] = = Num[j])
{
ch_id = Num[i];
Break
}
}
}

SYSTEM.OUT.PRINTLN ("Broken number is:" +dh_id);
System.out.println ("The heavy number is:" +ch_id);
}
}

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.