Problem 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
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;
class People{
String name ;
String to ;
String from ;
public People(String name , String from , String to )
{
this.name = name ;
this.to = to ;
this.from = from ;
}
}
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in) ;
int n =sc.nextInt() ;
People p[] = new People[n] ;
String str2[] = new String[n] ;
int cmd = 0 ;
int tag ;
String str1[] = {"zichuan","linzi","zhoucun","boshan"} ;
for(int i= 0 ; i<p.length ; i++)
{
tag = 1 ;
p[i] = new People(sc.next(),sc.next(),sc.next()) ;
for(int j= 0 ; j<cmd ; j++)
{
if(str2[j].equals(p[i].from))
{
tag = 0 ;
break ;
}
}
if(tag == 1)
{
str2[cmd++] = p[i].from ;
}
}
for(int i = 0 ; i<cmd ;i++)
{
System.out.print(str2[i]+" :");
for(int j= 0; j<p.length;j++)
{
if(str2[i].equals(p[j].from))
{
System.out.print(" "+p[j].name);
}
}
System.out.println();
}
for(int i= 0 ; i<str1.length ;i++)
{
System.out.print(str1[i]+" :");
for(int j= 0 ; j<p.length ; j++)
{
if(str1[i].equals(p[j].to))
{
System.out.print(" "+p[j].name);
}
}
System.out.println() ;
}
sc.close() ;
}
}