• 携程笔试


    1 判断链表有环

    2

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    import java.io.PrintWriter;
    import java.io.StreamTokenizer;
    import java.util.Scanner;
    
    public class z2 {
        //  [1,2,3,4,5]
    
        static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    
        static int nextInt() throws IOException {
            in.nextToken();
            return (int) in.nval;
        }
    
        static String next() throws IOException {
            in.nextToken();
            return (String) in.sval;
        }
    
        public static void main(String[] args) throws IOException {
            Scanner input = new Scanner(System.in);
            String str = input.nextLine();
            int k = input.nextInt();
            str = str.substring(1, str.length() - 1);
            
            String [] s = str.split(",");
            for(int i = 0; i < s.length / k; i++) { // 需要翻转的次数
    //            if((k & 1) != 0) { // 奇数,中间的不需要翻转
                    int start = i * k;
                    int end = start + k - 1;
                    String tmp = null;
                    while(start <= end) {
                        tmp = s[start];
                        s[start] = s[end];
                        s[end] = tmp;
                        start++;
                        end--;
                    }
    //            }
            }
            System.out.print("[");
            for(int i = 0; i < s.length; i++) {
                if(i != s.length - 1) {
                    System.out.print(s[i] + ",");
                }else {
                    System.out.print(s[i] + "]");
                }
            }
            System.out.println();
        }
    
    }
    View Code

    3.

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    import java.io.PrintWriter;
    import java.io.StreamTokenizer;
    import java.util.Scanner;
    
    public class z3 {
    
        static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    
        static int nextInt() throws IOException {
            in.nextToken();
            return (int) in.nval;
        }
    
        static String next() throws IOException {
            in.nextToken();
            return (String) in.sval;
        }
    
        public static void main(String[] args) throws IOException {
            Scanner input = new Scanner(System.in);
            int n = input.nextInt();
            String[] s = new String[n];
            for (int i = 0; i < n; i++) {
                s[i] = input.next();
    //            System.out.println(s[i]);
            }
    
            int num = 0;
            // path的前面一定是有/的,我根据前面的/来判定输出的数
            for (int i = 0; i < n; i++) {
                num = 1;
                if (s[i].charAt(s[i].length() - 1) == '/') {
    //                System.out.println(s[i] + " 最后是/");
                    s[i] = s[i].substring(0, s[i].length() - 1);
    //                System.out.println(s[i] + " 最后的/  已经去除了");
                }
                for (int j = 0; j < i; j++) {
                    if (s[i].equals(s[j])) {
                        num++;
                    }
                }
                String[] str = s[i].split("/");
    
                for (int k = 1; k < str.length; k++) {
                    if (k == 1 || k == str.length - 1) {
                        System.out.print(1);
                    } else {
                        System.out.print(num);
                    }
                }
                System.out.print(" ");
    
            }
    
        }
    
    }
    View Code

    转载于:https://www.cnblogs.com/Roni-i/p/10681449.html

  • 相关阅读:
    计算图像数据集RGB各通道的均值和方差
    多个数组的排列组合
    n个数中选取m个数,并全排列
    设计模式——代理模式
    简易的工厂模式
    多态
    final关键字特点
    this和super的区别
    重载与重写的区别
    Linux下安装MongoDB
  • 原文地址:https://www.cnblogs.com/twodog/p/12134936.html
Copyright © 2020-2023  润新知