2018网易互娱秋招笔试题

1. 计算税

import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t > 0) {
            solve(sc.nextInt());
            t--;
        }
        sc.close();
    }

    public static void solve(int n) {
        if (n <= 5000) {
            System.out.println(0);
            return;
        }
        double l0, l1, l2, l3, l4, l5, tax = 0;
        l0 = 3000 * 0.03;
        l1 = l0 + 0.1 * (12000 - 3000);
        l2 = l1 + 0.2 * (25000 - 12000);
        l3 = l2 + 0.25 * (35000 - 25000);
        l4 = l3 + 0.3 * (55000 - 35000);
        l5 = l4 + 0.35 * (80000 - 55000);

        n = n - 5000;
        if (n <= 3000) tax = 0.03 * n;
        else if (n <= 12000) tax = l0 + 0.1 * (n - 3000);
        else if (n <= 25000) tax = l1 + 0.2 * (n - 12000);
        else if (n <= 35000) tax = l2 + 0.25 * (n - 25000);
        else if (n <= 55000) tax = l3 + 0.3 * (n - 35000);
        else if (n <= 80000) tax = l4 + 0.35 * (n - 55000);
        else if (n > 80000) tax = l5 + 0.45 * (n - 80000);
        System.out.println(Math.round(tax));
    }
}

2. 成员列表

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        List names = new ArrayList<>(n);
        Map title = new HashMap<>(n);
        for (int i = 0; i < n; i++) {
            String[] strs = br.readLine().split(" ");
            title.put(strs[1], Integer.parseInt(strs[0]));
            names.add(strs[1]);
        }
        Map status = new HashMap<>(n);
        int m = Integer.parseInt(br.readLine());
        for (int i = 0; i < m; i++) {
            String[] strs = br.readLine().split(" ");
            status.put(strs[0], Integer.parseInt(strs[1]));
        }
        Collections.sort(names, (s1, s2) -> {
            if (status.get(s1) > status.get(s2))
                return -1;
            else if (status.get(s1) < status.get(s2))
                return 1;
            else if (title.get(s1) > title.get(s2))
                return -1;
            else if (title.get(s1) < title.get(s2))
                return 1;
            else
                return s1.compareTo(s2);
        });

        for (int i = 0; i < n; i++)
            System.out.println(names.get(i));

    }
}

3.时间区间

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.time.Duration;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

public class Main {

    static DateTimeFormatter dtf = DateTimeFormatter.ofPattern("HH:mm:ss");

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        for (int i = 0; i < t; i++) {
            int k = Integer.parseInt(br.readLine());
            TimeZone[] zones = new TimeZone[7];
            for (int j = 0; j < k; j++) {
                String[] str = br.readLine().split(" ");
                int day = Integer.parseInt(str[0]);
                int count = Integer.parseInt(str[1]);
                TimeZone timeZone = new TimeZone();
                timeZone.day = day - 1;
                timeZone.count = count;
                for (int s = 2; s < count + 2; s++) {
                    String[] time = str[s].split("-");
                    timeZone.startList.add(LocalTime.parse(time[0], dtf));
                    timeZone.endList.add(LocalTime.parse(time[1], dtf));
                }
                zones[day - 1] = timeZone;
            }

            int query = Integer.parseInt(br.readLine());
            for (int s = 0; s < query; s++) {
                String[] str = br.readLine().split(" ");
                int day = Integer.parseInt(str[0]);
                LocalTime now = LocalTime.parse(str[1], dtf);
                solve(zones, day - 1, now);
            }
        }
    }

    public static void solve(TimeZone[] zones, int day, LocalTime now) {
        if (zones[day] != null) {
            TimeZone timeZone = zones[day];
            for (int i = 0; i < timeZone.count; i++) {
                int flag = handleTime(now, timeZone.startList.get(i), timeZone.endList.get(i));
                if (flag == 0) {
                    System.out.println(0);
                    return;
                } else if (flag == -1) {
                    System.out.println(diff(now, timeZone.startList.get(i)));
                    return;
                }
            }
        }
        int next = (day + 1) % 7;
        while (zones[next] == null) {
            next = (next + 1) % 7;
        }
        if (next < day) next = next + 7;
        TimeZone timeZone = zones[next];
        long res = (next - day) * 24 * 3600 + diff(now, timeZone.startList.get(0));
        System.out.println(res);
    }

    public static int handleTime(LocalTime now, LocalTime start, LocalTime end) {
        if (now.isBefore(start)) return -1;
        else if (now.isAfter(end)) return -2;
        else return 0;
    }

    public static long diff(LocalTime now, LocalTime next) {
        Duration duration = Duration.between(now, next);
        return duration.toMillis() / 1000;
    }


    static class TimeZone {
        int day;
        int count;
        List startList;
        List endList;

        public TimeZone() {
            startList = new ArrayList<>();
            endList = new ArrayList<>();
        }
    }
}

 

你可能感兴趣的:(2018笔试题)