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

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

  • 相关阅读:
    双系统重装windows后,修复grub启动
    【转】GeoIP + PHP 完全指南
    【转】Linux压缩打包命令使用方法
    【转】linux screen 的使用 教程
    【转】tar打包命令详解
    【转】SecureCRT 显示乱码问题(总结)
    【转】Windows Server 2008 配置终端服务
    【转】vsftp 添加用户 简单步骤
    【转】用移动硬盘装WIN7出现NTLDR is missing
    【转】Qt集成到VS2008中 ( Qt4.5.1 + qtvsaddin1.0.0 )
  • 原文地址:https://www.cnblogs.com/twodog/p/12134936.html
Copyright © 2011-2022 走看看