Description
淄博某旅行社每天都要接待来自全国各地的游客,他们从各个城市来到张店区,游玩后又去淄博的其他旅游景点。从各个城市来张店的游客只是在网上报名,然后旅行社根据统计的人数,用大巴把他们从不同城市拉到张店。在张店玩一天后,这些游客又要到淄博其他景点玩,所以重新统计到淄川、临淄、周村、博山去的游客,用大巴把他们分送过去。
统计这些游客是很费精力的,但让电脑做会简单一些,现在就请你帮忙设计这个程序统计分送的游客。
Input
第一行是一个正整数n(n <= 100) ,代表网上报名人数。接下来n行,每行包括一个name(字符串,不超过20个字符),来的城市from(字符串,英文小写,不超过20个字符),去的城市to(只有zichuan,linzi,zhoucun,boshan中的一个),名单顺序代表报名顺序,也是优先处理顺序。
Output
对于每个始发城市,先输出始发城市名,冒号,从此城市来的游客名单。
对要去的目的地,先输出目的地城市,冒号,到此城市的游客名单。目的地城市只有题中已经告诉的四个,并按题中提到的顺序输出,对于没有要去的城市也要输出。
在名单前列的人名输出时要先于在名单后面的。更详细的输入输出见示例。
Sample
Input
6
skym zoucheng linzi
plmm beijing boshan
moon jinan boshan
pc zoucheng zichuan
von shanghai boshan
qq beijing zichuan
Output
zoucheng : skym pc
beijing : plmm qq
jinan : moon
shanghai : von
zichuan : pc qq
linzi : skym
zhoucun :
boshan : plmm moon von
Hint
import java.util.*;
class Per {
String name, from, to;
boolean flag = true;
public Per(String name, String from, String to) {
super();
this.name = name;
this.from = from;
this.to = to;
}
}
public class Main {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
Per[] per = new Per[1000];
int n = reader.nextInt();
for (int i = 0; i < n; i++) {
per[i] = new Per(reader.next(), reader.next(), reader.next());
}
for (int i = 0; i < n; i++) {
if (per[i].flag) {
System.out.print(per[i].from + " : " + per[i].name);
per[i].flag = false;
for (int j = i + 1; j < n; j++) {
if (per[j].from.compareTo(per[i].from) == 0) {
System.out.print(" " + per[j].name);
per[j].flag = 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 (per[j].to.compareTo(map[i]) == 0) {
System.out.print(" " + per[j].name);
}
}
System.out.println();
}
reader.close();
}
}