Question 1: Dinner
Timelimit: 1 s
Memorylimit: 32 m
DescriptionLittle 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.
InputThere 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.
OutputFor each test of the input, output all the name of tableware. For each group of test data, output The Name Of The tableware.
Sample Input3 Basketball fork chopsticks2 bowl letter
Sample outputFork chopsticksbowl
Hint:The tableware only contains: bowl, knife, fork and chopsticks.
SolutionsObtain the item set from the input and determine whether it is a tableware. The reference code is as follows:/** dinner */public static void test7 (invalid parameters) {string [] S = new string [] {"bowl", "Knife ", "fork", "Chopsticks"}; int n = average. nextint (); int Index = 0; For (INT I = 0; I <n; I ++) {string temp = temperature. 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
DescriptionRecently, 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.
InputThere 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.
OutputFor 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 Input51 32 43 54 65 661 32 43 54 65 76 7
Sample outputYou are my elderyou are my brother
SolutionsA 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 = unknown. nextint (); int [] DATA = new int [n + 1]; for (INT I = 0; I <n; I ++) {int A = random. nextint (); int B = bytes. 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");} else if (d1 = d2) {system. out. println ("you are my brother");} else {system. out. println ("you are my younger ");}}
Question 3: Time
Timelimit: 1 s
Memorylimit: 32 m
DescriptionDigital Clock use 4 digits to express time, each digit is described by 3*3 characters (including "|", "_" and "). now given the current time, please tell us how can it be expressed by the digital clock.
InputThere are several test cases. Each case contains 4 integers in a line, separated by space. Proceed to the end of file.
OutputFor each test case, output the time expressed by the digital clock such as sample output.
Sample Input1 2 5 62 3 4 2
Sample output_ | _
Hint:The digits showed by the digital clock are as follows: _ | | _ |
SolutionsFrom the output result, three rows are output, namely the upper and lower sections, and three sections are output in the program. The reference code is as follows:/** time */public static void test8 (invalid parameters) {string [] [] time = new string [] [] {"_", "","_","_","","_","_","_","_","_"}, {"|", "|", "_ |", "_ |", "| _ |", "| _", "| _", "| ", "| _ |", "| _ |" },{ "| _ |", "|", "| _", "_ |", "| ", "_ |", "| _ |", "|", "| _ |", "_ |" }}; int A [] = new int [4]; for (INT I = 0; I <4; I ++) {A [I] = random. nextint () ;}for (INT I = 0; I <3; I ++) {for (Int J = 0; j <4; j ++) {system. out. print (time [I] [A [J]);} system. out. println ();}}
Li xucheng csdn blog: http://blog.csdn.net/javaeeteacher