# ACM详解（10）——辽宁省赛（上）

第一题：Dinner

Timelimit: 1s  Memorylimit:32M
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 many 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 many 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. 对于每组测试数据，输出餐具的名字。
Sample Input
3 basketball fork chopsticks
2 bowl letter
Sample Output
fork chopsticks
bowl
HINT
The tableware only contains: bowl, knife, fork and chopsticks.

/*
* Dinner
*/
public static void test7(Scanner scanner){
String[] s=new String[]{"bowl","knife","fork","chopsticks"};
int n=scanner.nextInt();
int index=0;
for(int i=0;i<n;i++){
String temp = scanner.next();
for(String temp2:s){
if(temp.equals(temp2)){
if(index!=0)
System.out.print(" ");
System.out.print(temp);
index++;
break;
}
}
}
System.out.println();
}

Timelimit: 1s  Memorylimit:32M
Description

Input
There are several test cases.

Proceed to the end of file.
Output

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

500 年前是一家，意味着他们有共同的祖先，所以只要找到他们共同的祖先，然后算出来他们分别属于第几代子孙，就可以知道他们之间的关系了。因为每个人只能有一个父亲，所以可以使用数组下标与元素值来表示孩子与父亲的关系，例如a[4]=8 ，表示第5 个人的父亲是第8 个人。

/*
* you are my brother
*/
public static void test6(Scanner scanner){
int n=scanner.nextInt();
int[] data = new int[n+1];
for(int i=0;i<n;i++){
int a=scanner.nextInt();
int b=scanner.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");
}
}

Timelimit: 1s  Memorylimit:32M
Description
Digital 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.
Input
There are several test cases.
Each case contains 4 integers in a line, separated by space.
Proceed to the end of file.
Output
For each test case, output the time expressed by the digital clock such as Sample Output.
Sample Input
1 2 5 6
2 3 4 2
Sample Output
_ _ _
| _||_ |_
||_ _||_|
_ _     _
_| _||_| _|
|_ _| ||_
HINT
The digits showed by the digital clock are as follows:
_ _     _ _ _ _ _ _
| _| _||_||_ |_   ||_||_|| |
||_ _| | _||_| ||_| _||_|

/*
* Time
*/
public static void test8(Scanner scanner){
String[][] time=new String[][]{
{" _ "," "," _ "," _ ","   "," _ "," _ "," _ "," _ "," _ "},
{"| |"," |"," _|"," _|","|_|","|_ ","|_ "," |","|_|","|_|"},
{"|_|"," |","|_ "," _|"," |"," _|","|_|"," |","|_|"," _|"}};
int a[]=new int[4];
for(int i=0;i<4;i++){
a[i] = scanner.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();
}
}

• 点赞
• 评论 7
• 分享
x

海报分享

扫一扫，分享海报

• 收藏
• 手机看

分享到微信朋友圈

x

扫一扫，手机阅读

• 打赏

打赏

老李-大连

你的鼓励将是我创作的最大动力

C币 余额
2C币 4C币 6C币 10C币 20C币 50C币
• 一键三连

点赞Mark关注该博主, 随时了解TA的最新博文
10-23
03-15 2618

04-28 895
05-12 4489
02-14 747
08-28 1532
05-22 2068
07-23 3188
11-04 2145
05-08 1万+
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客