版权声明:iQXQZX https://blog.csdn.net/Cherishlife_/article/details/86380880
来淄博旅游
Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
淄博某旅行社每天都要接待来自全国各地的游客,他们从各个城市来到张店区,游玩后又去淄博的其他旅游景点。从各个城市来张店的游客只是在网上报名,然后旅行社根据统计的人数,用大巴把他们从不同城市拉到张店。在张店玩一天后,这些游客又要到淄博其他景点玩,所以重新统计到淄川、临淄、周村、博山去的游客,用大巴把他们分送过去。
统计这些游客是很费精力的,但让电脑做会简单一些,现在就请你帮忙设计这个程序统计分送的游客。
Input
第一行是一个正整数n(n <= 100) ,代表网上报名人数。接下来n行,每行包括一个name(字符串,不超过20个字符),来的城市from(字符串,英文小写,不超过20个字符),去的城市to(只有zichuan,linzi,zhoucun,boshan中的一个),名单顺序代表报名顺序,也是优先处理顺序。
Output
对于每个始发城市,先输出始发城市名,冒号,从此城市来的游客名单。
对要去的目的地,先输出目的地城市,冒号,到此城市的游客名单。目的地城市只有题中已经告诉的四个,并按题中提到的顺序输出,对于没有要去的城市也要输出。
在名单前列的人名输出时要先于在名单后面的。更详细的输入输出见示例。
Sample Input
扫描二维码关注公众号,回复:
5068003 查看本文章
6
skym zoucheng linzi
plmm beijing boshan
moon jinan boshan
pc zoucheng zichuan
von shanghai boshan
qq beijing zichuan
Sample Output
zoucheng : skym pc
beijing : plmm qq
jinan : moon
shanghai : von
zichuan : pc qq
linzi : skym
zhoucun :
boshan : plmm moon von
Hint
Source
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
list[] l = new list[101];
int n = in.nextInt();
for (int i = 0; i < n; i++) {
l[i] = new list(in.next(), in.next(), in.next());
}
for (int i = 0; i < n - 1; i++) {
if (l[i].mark) {
System.out.print(l[i].from + " : " + l[i].name);
l[i].mark = false;
for (int j = i + 1; j < n; j++) {
if (l[j].from.compareTo(l[i].from) == 0) {
System.out.print(" " + l[j].name);
l[j].mark = false;
}
}
System.out.println();
}
}
String[] map = new String[]{
"zichuan",
"linzi",
"zhoucun",
"boshan"
};
for (int i = 0; i < 4; i++) {
System.out.print(map[i] + " :");
for (int j = 0; j < n; j++) {
if (l[j].wanto.compareTo(map[i]) == 0)
System.out.print(" " + l[j].name);
}
System.out.println();
}
}
}
class list {
String name; // 名字
String from; // 来自
String wanto; // 目的地
boolean mark = true; // 标记
public list(String name, String from, String wanto) {
this.name = name;
this.from = from;
this.wanto = wanto;
}
}