zoukankan      html  css  js  c++  java
  • 携程笔试

    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
  • 相关阅读:
    让8个数码管全部显示数字
    程序存储空间与内存
    点亮数码管,显示具体的数字
    为什么点亮小灯时,有时是输入数字0,有时是数字1
    循环点亮LED灯
    keil 编程时,总是中英文切换时,格式混乱。
    点亮LED灯
    学生管理系统(C 大一期末作业)
    ivew ui
    git常见操作
  • 原文地址:https://www.cnblogs.com/Roni-i/p/10681449.html
Copyright © 2011-2022 走看看