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 }
  • 相关阅读:
    常用函数工具记录贴
    phpCAS::handleLogoutRequests()关于java端项目登出而php端项目检测不到的测试
    Cas服务器设置(java),java、php客户端配置
    android导入项目出现R文件不能生成
    Error executing aapt: Return code -1073741819
    网页在线播发视频 在线查看文档
    jeecg的cq查询方式
    威佐夫博弈
    HDU 1850 (尼姆博奕)
    HDU2149 (巴什博弈)
  • 原文地址:https://www.cnblogs.com/EpisodeXI/p/4067122.html
Copyright © 2011-2022 走看看