NYOJ 540

简介:   为了给学弟学妹讲课,我水了一道题…… import java.util.Arrays; import java.util.Scanner; public class NYOJ540 { public static void main(String[] args) { ...

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

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;
    }
}
目录
相关文章
|
测试技术
NYOJ 541
  最强DE 战斗力 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 春秋战国时期,赵国地大物博,资源非常丰富,人民安居乐业。但许多国家对它虎视眈眈,准备联合起来对赵国发起一场战争。
751 0
|
JavaScript
NYOJ&#160;17
时间限制:3000 ms  |  内存限制:65535 KB 难度:4 描述 求一个字符串的最长递增子序列的长度 如:dabdbf最长递增子序列就是abdf,长度为4 输入 第一行一个整数0 随后的n行,每行有一个字符串,该字符串的长度不会超过10000 输出 输出字符串的最长递增子序列的长度 样例输入 3 aaa ababc abklmncdefg 样例输出 1 3 7 题目很经典,学习一下吧。
644 0
NYOJ 205
  求余数 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 现在给你一个自然数n,它的位数小于等于一百万,现在你要做的就是求出这个数除10003之后的余数   输入 第一行有一个整数m(1T; 13 scanf("%*c")...
666 0
NYOJ 506
  洗澡 时间限制:1000 ms  |  内存限制:65535 KB 难度:1   描述 Mostrp是个爱干净的好少年。 有一次去澡堂洗澡时发现 澡堂的澡柜编号中没有出现过数字‘4’。
794 0
NYOJ 283
1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 /* 9 bool cmp(char *a,char *b) 10...
470 0
|
人工智能
NYOJ 138
  找球号(二) 时间限制:1000 ms | 内存限制:65535 KB 难度:5   描述 在某一国度里流行着一种游戏。游戏规则为:现有一堆球中,每个球上都有一个整数编号i(00) pos=(pos+1)%N; ch[pos]=num; } ...
788 0
NYOJ 113
1 #include 2 #include 3 using namespace std; 4 5 int main() 6 { 7 int pos=-1; 8 string s; 9 while(getline(cin,s)) 10 { 11 while((pos=s.
659 0
NYOJ 366
View Code 1 #include 2 #include 3 #include 4 using namespace std; 5 6 int main() 7 { 8 int i,j,k,T; 9 int n; 10 ...
743 0
NYOJ 86
  找球号(一) 时间限制:3000 ms | 内存限制:65535 KB 难度:3   描述 在某一国度里流行着一种游戏。游戏规则为:在一堆球中,每个球上都有一个整数编号i(0
788 0