zoukankan      html  css  js  c++  java
  • PAT 1025

    PAT 1025,需要注意的一个坑是当分数相同的时候,按照id从小到大排序

    package pat.pat_1025;
    
    // 坑,当分数相同的时候按照id顺序排序
    
    import java.util.*;
    import java.io.*;
    
    class FastReader{
        BufferedReader reader;
        StringTokenizer tokenizer;
        
        public FastReader(InputStream stream){
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }
        
        public String next(){
            while (tokenizer == null || !tokenizer.hasMoreTokens()){
                try{
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            
            return tokenizer.nextToken();
        }
        
        public int next_int(){
            return Integer.parseInt(next());
        }
    }
    
    class Testee{
        String id;
        int score;
        
        int location_num;
        int location_rank;
        int final_rank;
    }
    
    public class Main {
        public static void main(String[] args){
            FastReader reader = new FastReader(System.in);
            int N = reader.next_int();
            
            ArrayList<Testee> global_testee = new ArrayList<Testee>();
            for (int i = 0; i < N; i++){
                int K = reader.next_int();
                ArrayList<Testee> local_testee = new ArrayList<Testee>();
                for (int j = 0; j < K; j++){
                    Testee testee = new Testee();
                    testee.id = reader.next();
                    testee.score = reader.next_int();
                    testee.location_num = i + 1;
                    
                    local_testee.add(testee);
                    global_testee.add(testee);
                }
                
                Collections.sort(local_testee, new Comparator<Testee>(){
                    public int compare(Testee t1, Testee t2) {
                        if (t2.score != t1.score)
                            return t2.score - t1.score;
                        else
                            return t1.id.compareTo(t2.id);
                    }
                });
                
                int cur_rank = 1;
                local_testee.get(0).location_rank = cur_rank;
                for (int k = 1; k < local_testee.size(); k++){
                    cur_rank++;
                    if (local_testee.get(k).score == local_testee.get(k - 1).score)
                        local_testee.get(k).location_rank = local_testee.get(k - 1).location_rank;
                    else
                        local_testee.get(k).location_rank = cur_rank;
                }
            }
            
            Collections.sort(global_testee, new Comparator<Testee>(){
                public int compare(Testee t1, Testee t2) {
                    if (t2.score != t1.score)
                        return t2.score - t1.score;
                    else
                        return t1.id.compareTo(t2.id);
                }
            });
            int cur_rank = 1;
            global_testee.get(0).final_rank = cur_rank;
            for (int k = 1; k < global_testee.size(); k++){
                cur_rank++;
                if (global_testee.get(k).score == global_testee.get(k - 1).score)
                    global_testee.get(k).final_rank = global_testee.get(k - 1).final_rank;
                else
                    global_testee.get(k).final_rank = cur_rank;
            }
            
            System.out.println(global_testee.size());
            for (int i = 0; i < global_testee.size(); i++){
                Testee cur_testee = global_testee.get(i);
                System.out.println(cur_testee.id + " " + cur_testee.final_rank + " " + cur_testee.location_num + " " + cur_testee.location_rank);
            }
        }
    }
  • 相关阅读:
    基于WINCE6.0+S3C2443的camera驱动
    WINCE下基于SL031的RFID功能的实现
    WINCE6.0+S3C2443下的activesync问题
    WINCE6.0+S3C2443下WatchDog学习
    错误的抉择,痛悔
    WINCE5.0下SQL server compact版本更新
    做生意和打工的区别
    WINCE基于MC8630的3G模块的控制和加载
    Xml Tips
    VB.NET and C# Comparison
  • 原文地址:https://www.cnblogs.com/EpisodeXI/p/4066084.html
Copyright © 2011-2022 走看看