zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    读书笔记之理想设计的特征
    一些javascript 变量声明的 疑惑
    LINQ 使用方法
    Google MySQL tool releases
    读书笔记之设计的层次
    EF之数据库连接问题The specified named connection is either not found in the configuration, not intended to be used with the Ent
    转载 什么是闭包
    javascript面向对象起步
    Tips
    数据结构在游戏中的应用
  • 原文地址:https://www.cnblogs.com/EpisodeXI/p/4067122.html
Copyright © 2011-2022 走看看