下沉的船
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 Jackimport 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++; } } }