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
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);
}
}
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