zoukankan      html  css  js  c++  java
  • NYOJ 540

      为了给学弟学妹讲课,我水了一道题……

    import java.util.Arrays;
    import java.util.Scanner;
    
    public class NYOJ540 {
    
        public static void main(String[] args) {
            int from, to, T;
            Node node[];
            Scanner sc = new Scanner(System.in);
            T = sc.nextInt();
            int temp;
            while(T-->0) {
                from = sc.nextInt();
                to = sc.nextInt();
                node = new Node[to-from+1];
                int j = 0;
                for(int i=0; i<node.length; i++) {
                    //q已经初始化为0了
                    node[i] = new Node();
                }
                for(int i=from; i<=to; i++) {
                    node[j].p = i;
                    temp = i;
                    while(temp>0) {
                        /*
                         * 必须在大while循环构造node数组
                         * 否则就第一组数据正确
                         * 因为下面这一句用到了以前的q值
                         */
                        node[j].q = node[j].q*10 + temp%10;
                        temp /= 10;
                    }
                    j++;
                }
                /*
                 * 只看API函数,第三个参数是toIndex,以为是下标
                 * 谁知道具体一看不包括,wa了n次
                 */
                Arrays.sort(node,0,to-from+1);
                System.out.print(node[0].p);
                for(int i=1; i<to-from; i++) {
                    System.out.print(" "+node[i].p);
                }
                System.out.println(" "+node[to-from].p);
            }
        }
    }
    
    class Node implements Comparable<Node>{
        int p;
        int q;
        
        public Node() {
            this.p = 0;
            this.q = 0;
        }
    
        @Override
        public int compareTo(Node o) {
            // TODO Auto-generated method stub
            Node other = o;
            return this.q - other.q;
        }
    }
  • 相关阅读:
    git问题记录
    @Slf4j注解
    idea修改maven项目名
    spring的定时任务schedule
    @RequestParam详解
    统一全局异常处理将出错的栈信息打印到日志中
    python交互环境中导入文件中自定义的函数报错
    关于服务器的小技巧
    Python学习
    前后端分离时,获取不到session
  • 原文地址:https://www.cnblogs.com/hxsyl/p/3235819.html
Copyright © 2011-2022 走看看