【攒人品】携程 3.29 笔试前三题

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        char[] ss = s.toCharArray();
        int count = 0;
        for (int i = 0; i < ss.length; i++) {
            if(ss[i] == '0' || ss[i] == '6' || ss[i] == '9'){
                count ++;
            }
            else if(ss[i] == '8'){
                count += 2;
            }
        }
        System.out.println(count);
    }
}

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        List<Integer> list = new ArrayList<>();
        int y = n;
        for (int i = 0; i < k; i ++) {
            list.add(y - k + i + 1);
        }
        if (list.size() < n){
            for (int i = 0; i < n - k; i++) {
                if(2 * i + 1 <= list.size()){
                    list.add(2 * i + 1, i + 1);
                } else {
                    list.add(i + 1);
                }
            }
        }
        
        for (int i = 0; i < n; i++) {
            System.out.print(list.get(i)+" ");
        }
    }
}

import java.util.Scanner;

public class Main3 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long n = scanner.nextLong();
        long y = 0, min = n;
        long x_1 = 2, x = 2;
        long min_x = 1, min_y=1;
        while(x_1 <= 10000000000L){
            if (x != 2){
                y = n / (x_1 - 1);
                for (long i = y - 1; i <= y + 1; i++) {
                    if(i != 2 && i > 0){
                        long abs = Math.abs(n-(x_1-1)*i);
                        if(min > abs){
                            min = abs;
                            min_x = x;
                            min_y = i;
                        }
                    }
                }
            }
            x_1 = x_1 * (++x);
        }
        System.out.println(min_x+" "+min_y);
    }
}

方法要是太笨的话,大家轻点喷,另求一道AC的第四题解答(感动)

#携程#
全部评论
C++写的 树形dp
点赞 回复 分享
发布于 2023-03-31 09:25 河南
佬的第三题全ac啦?
点赞 回复 分享
发布于 2023-03-29 23:21 湖北

相关推荐

frutiger:逆天,我家就安阳的,这hr咋能说3k的,你送外卖不比这工资高得多?还说大厂来的6k,打发叫花子的呢?这hr是怎么做到说昧良心的话的
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
2
3
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务