首页 > 代码库 > PAT 1028
PAT 1028
这道题JAVA能超时我也是无奈了,感觉没啥办法了,自求多福吧... 换python更跪,C++又是VC 6.0,紫金港你特么能不能成点事啊>_<
1 import java.util.*; 2 import java.io.*; 3 4 class FastReader{ 5 BufferedReader reader; 6 StringTokenizer tokenizer; 7 8 public FastReader(InputStream stream){ 9 reader = new BufferedReader(new InputStreamReader(stream), 123456789);10 tokenizer = null;11 }12 13 public String next(){14 while (tokenizer == null || !tokenizer.hasMoreTokens()){15 try{16 tokenizer = new StringTokenizer(reader.readLine());17 } catch (Exception e){18 throw new RuntimeException(e);19 }20 }21 22 return tokenizer.nextToken();23 }24 25 public int next_int(){26 return Integer.parseInt(next());27 }28 }29 30 class StudentInfo{31 String id;32 String name;33 int grade;34 }35 36 public class Main {37 public static void main(String[] args){38 FastReader reader = new FastReader(System.in);39 int N = reader.next_int();40 int C = reader.next_int();41 42 ArrayList<StudentInfo> students = new ArrayList<StudentInfo>();43 for (int i = 0; i < N; i++){44 StudentInfo s = new StudentInfo();45 s.id = reader.next();46 s.name = reader.next();47 s.grade = reader.next_int();48 49 students.add(s);50 }51 52 if (C == 1){53 Collections.sort(students, new Comparator<StudentInfo>(){54 public int compare(StudentInfo s1, StudentInfo s2){55 return s1.id.compareTo(s2.id);56 }57 });58 } else if (C == 2){59 Collections.sort(students, new Comparator<StudentInfo>(){60 public int compare(StudentInfo s1, StudentInfo s2){61 if (!s1.name.equals(s2.name))62 return s1.name.compareTo(s2.name);63 else{64 return s1.id.compareTo(s2.id);65 }66 }67 });68 } else {69 Collections.sort(students, new Comparator<StudentInfo>(){70 public int compare(StudentInfo s1, StudentInfo s2){71 if (s1.grade != s2.grade)72 return s1.grade - s2.grade;73 else{74 return s1.id.compareTo(s2.id);75 }76 }77 });78 }79 80 for (StudentInfo s : students){81 System.out.println(s.id + " " + s.name + " " + s.grade);82 }83 }84 }
PAT 1028
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。