博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PAT 1028
阅读量:4711 次
发布时间:2019-06-10

本文共 2826 字,大约阅读时间需要 9 分钟。

这道题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
students = new ArrayList
();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
(){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
(){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
(){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 }

 

转载于:https://www.cnblogs.com/EpisodeXI/p/4067122.html

你可能感兴趣的文章
VS2013 F12无法转到函数的定义处,总是从“元数据”获取的问题 ——解决方法...
查看>>
Python列表list对象方法总结
查看>>
jjs 产生undefined的情况
查看>>
chrome的uget扩展程序红色 Unable to connect with uget-integrator问题
查看>>
16 个免费和收费的视频、多媒体 WordPress 主题
查看>>
noip2018游记
查看>>
[SCOI2008]配对
查看>>
尚学堂Spring视频教程(七):AOP XML
查看>>
PHP 常用函数库和一些实用小技巧
查看>>
互联网架构消息队列
查看>>
day5_生成进度条的程序
查看>>
Linux内核之于红黑树and AVL树
查看>>
招聘一个靠谱的iOS
查看>>
使用Xunit进行单元测试
查看>>
TCP的三次握手和四次握手
查看>>
创建用户、授权SCHEMA
查看>>
python学习笔记
查看>>
zoj 3229 有源汇有上下界的最大流模板题
查看>>
Python使用mechanize模拟浏览器
查看>>
android调用音乐播放器,三种方
查看>>