酒店价格、集合、文件名称

来源:互联网 发布:北京哪个java培训班好 编辑:程序博客网 时间:2024/06/11 04:09

/**
* 题目描述 酒店房间的价格录入是通过时间段来录入的,比如10月1日至10月7日800元,10月8日至10月20日500元,请实现以下函数int[][]
* merge(int[][]
* dateRangePrices),输入是某个酒店多个日期段的价格,每个日期段(终止日期大于等于起始日期)和对应的价格使用长度为3的数组来表示,比如[0,
* 19, 300], [10, 40,
* 250]分别表示从某天开始第1天到第20天价格都是300,第11天到第41天价格都是250,这些日期端有可能重复,重复的日期的价格以后面的为准,
* 请以以下规则合并并输出合并结果: 1.相邻两天的价格如果相同,那么这两个日期段应该合并 2.合并的结果应该以起始日期从小到大排序 输入描述:
* 输入数据包括多行,如样例输入所示。 输出描述: 输出数据为一行,如样例输出所示 示例1 输入
*
* 1 1 100 2 3 100 4 5 110 输出
*
* [1, 3, 100],[4, 5, 110]
*
* @author MaiBenBen
*/

public class HotelMoney {    /**     * @param args the command line arguments     */    public static void main(String[] args) {        // TODO code application logic here        Scanner in = new Scanner(System.in);        int[] a = new int[1000];        int min = Integer.MAX_VALUE;        int max = Integer.MIN_VALUE;        while (in.hasNext()) {            int x = in.nextInt();            int y = in.nextInt();            int z = in.nextInt();            for (int i = x; i <= y; i++) {                a[i] = z;            }            if (x < min) {                min = x;            }            if (y > max) {                max = y;            }        }        System.out.print("[" + min + ", ");        for (int i = min; i < max; i++) {            if (a[i] != a[i + 1]) {                if (a[i] != 0) {                    System.out.print(i + ", " + a[i] + "],");                }                if (a[i + 1] != 0) {                    System.out.print("[" + (i + 1) + ", ");                }            }            a[i] = a[i + 1];        }        System.out.println(max + ", " + a[max] + "]");    }}

输入描述:
* 输入数据为一个文件路径 输出描述: 对于每个测试实例,要求输出对应的filename extension 示例1 输入
*
* Abc/file.txt 输出
*
* txt
*
* @author MaiBenBen
*/

public class FileName {    /**     * @param args the command line arguments     */    public static void main(String[] args) {        // TODO code application logic here        Scanner in = new Scanner(System.in);        String str = in.next();        int pos=str.lastIndexOf(".");        if(pos==-1||str.charAt(pos+1)=='/'){            System.out.println("null");        }else{            System.out.println(str.substring(pos+1));        }    }}
public class JiHe {    /**     *     * 题目描述 给你两个集合,要求{A} + {B}。 注:同一个集合中不会有两个相同的元素。 输入描述:     * 每组输入数据分为三行,第一行有两个数字n,m(0 ≤ n,m ≤     * 10000),分别表示集合A和集合B的元素个数。后两行分别表示集合A和集合B。每个元素为不超过int范围的整数,每个元素之间有个空格隔开。     * 输出描述: 针对每组数据输出一行数据,表示合并后的集合,要求从小到大输出,每个元素之间有一个空格隔开,行末无空格。 示例1 输入     *     * 3 3     * 1 3 5     * 2 4 6     * 输出     *     * 1 2 3 4 5 6     *     * @param args the command line arguments     */    public static void main(String[] args) {        // TODO code application logic here        Scanner in = new Scanner(System.in);        int a = in.nextInt();        int b = in.nextInt();        Set<Integer> s = new TreeSet<>();        for (int i = 0; i < a; i++) {            s.add(in.nextInt());        }        for (int j = 0; j < b; j++) {            s.add(in.nextInt());        }        Iterator<Integer> iterator = s.iterator();        while (iterator.hasNext()) {            System.out.print(iterator.next());            if (iterator.hasNext()) {                System.out.print(" ");            }        }//        int[] a1 = new int[a];//        int[] b1 = new int[b];//        for (int i = 0; i < a; i++) {//            a1[i] = in.nextInt();//        }//        for (int i = 0; i < b; i++) {//            b1[i] = in.nextInt();//        }//        gamea(a1, b1);//    }////    private static void gamea(int[] a, int[] b) {//        int alen = a.length;//        int blen = b.length;//        int[] c = new int[alen + blen];//        for(int i=0;i<alen+blen;i++){//            if(i<alen){//                c[i]=a[i];//            }else{//                c[i]=b[i-alen];//            }//        }//        HashSet<Integer> hashSet=new HashSet<>();//        Arrays.sort(c);//         for (Integer q : c) {//             hashSet.add(q);//        }//         Iterator<Integer> integers=hashSet.iterator();boolean flag=true;//         while(integers.hasNext()){//             if(flag){//                 System.out.print(integers.next());flag=false;//             }else{//                 System.out.print(" "+integers.next());//             }//         }    }}
原创粉丝点击