ACM (10)-Liaoning Province (I)

Source: Internet
Author: User

Question 1: Dinner

Timelimit: 1 s Memorylimit: 32 M
Description
Little A is one member of ACM team. he had just won the gold in World Final. to celebrate, he decided to invite all to have one meal. as bowl, knife and other tableware is not enough in the kitchen, Little A goes to take backup tableware in warehouse. there are using boxes in warehouse, one box contains only one thing, and each box is marked by the name of things inside it. for example, if "basketball" is written on the box, which means the box contains only basketball. with these marks, Little A wants to find out the tableware easily. so, the problem for you is to help him, find out all the tableware from all boxes in the warehouse.
Input
There are pending test cases. each case contains one line, and one integer N at the first, N indicates that there are N boxes in the warehouse. then N strings follow, each string is one name written on the box.
Output
For each test of the input, output all the name of tableware. For each group of test data, output the name of the tableware.
Sample Input
3 basketball fork chopsticks
2 bowl letter
Sample Output
Fork chopsticks
Bowl
HINT:
The tableware only contains: bowl, knife, fork and chopsticks.
Solutions
Obtain the item set from the input and determine whether it is a tableware. The reference code is as follows:
/*
* Dinner
*/
Public static void test7 (synchronized ){
String [] s = new String [] {"bowl", "knife", "fork", "chopsticks "};
Int n = response. nextInt ();
Int index = 0;
For (int I = 0; I <n; I ++ ){
String temp = parameters. next ();
For (String temp2: s ){
If (temp. equals (temp2 )){
If (index! = 0)
System. out. print ("");
System. out. print (temp );
Index ++;
Break;
}
}
}
System. out. println ();
}
 
Question 2: You are my brother
Timelimit: 1 s Memorylimit: 32 M
Description
Recently, Little A met A new friend, Little B. During their chat, they found that they were A family before 500. Now Little A wants to know that Little is his elder and younger generation, brother.
Input
There are several test cases.
Each group of test data first enters an integer N (N <= 1000), followed by N rows, each line has two integers a, and B indicates that the father of a is B (1 <=, B <= 2000 ). The number of Little is 1, and the number of Little is 2. Each person can have only one father.
Proceed to the end of file.
Output
For each group of test data, if Little B is the younger generation of Little A, "You are my younger" is output. If Little B is the elder of Little, "You are my elder" is output, and "You are my brother" is output if it is a peer ".
Sample Input
5
1 3
2 4
3 5
4 6
5 6
6
1 3
2 4
3 5
4 6
5 7
6 7
Sample Output
You are my elder
You are my brother
Solutions
A family before 500 means that they had a common ancestor, so as long as they found their common ancestor and figured out that they belonged to the generations respectively, they could know the relationship between them. Because each person can only have one parent, you can use the array subscript and element value to indicate the relationship between the child and the father. For example, a [4] = 8 indicates that the father of 5th people is 8th People.
The reference code is as follows:
/*
* You are my brother
*/
Public static void test6 (writable ){
Int n = response. nextInt ();
Int [] data = new int [n + 1];
For (int I = 0; I <n; I ++ ){
Int a = response. nextInt ();
Int B = response. nextInt ();
Data [A-1] = B;
}
Int d1 = 0;
Int d2 = 0;
Int temp = 1;
While (data [temp-1]! = 0 ){
D1 ++;
Temp = data [temp-1];
}
Temp = 2;
While (data [temp-1]! = 0 ){
D2 ++;
Temp = data [temp-1];
}
If (d1> d2 ){
System. out. println ("You are my elder ");
& N

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.