下沉的船

下沉的船

Time Limit: 1000MS  Memory Limit: 65536KB
Problem Description

身份优先级: woman = child > man > captain.

多组数据(少于组),每一组有一个整数,代表船上有个人,接下来行,每行有一个名字和他的身份。名字字符长度小于。数据保证不存在重名,注意可能存在多名船长

Output
 输出n行,每一行输出一个名字,先上船的名字在前面。
Example Input
6
Jack captain
Alice woman
Charlie man
Teddy woman
Bob child
Julia woman
Example Output
Alice
Teddy
Bob
Julia
Charlie
Jack
import java.util.Scanner;  
  
public class Main {  
  
    public static void main(String[] args) {  
     Scanner reader = new Scanner(System.in);
      int p = 1;
      while(p < 10){
    	  int n = reader.nextInt();
    	  String a[] = new String[101];
    	  String b[] = new String[101];
    	  int c[] = new int[101];
    	  for(int i = 0; i < n; i++){
    		  a[i] = reader.next();
    		  b[i] = reader.next();
    		  if(b[i].equals("captain")){
    			  c[i] = 3;
    		  }
    		  else if(b[i].equals("woman")||b[i].equals("child")){
    			  c[i] = 1;
    		  }
    		  else if(b[i].equals("man")){
    			  c[i] = 2;
    		  }
    	  }
    		  for(int i = 0; i < n-1; i++){
    			  for(int j = 0; j < n-i-1; j++){
    				  if(c[j] > c[j+1]){
    					  int y = c[j];
    					  c[j] = c[j+1];
    					  c[j+1] = y;
    					  String s = a[j];
    					  a[j] = a[j+1];
    					  a[j+1] = s;
    				  }
    			  }
    		  }
    		  for(int i = 0; i < n; i++){
    			  System.out.println(a[i]);
    	  }
    		  p++;
      }
    }
}  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值