网易惨败,190?160?

网易第一题:

import java.util.Scanner;

public class Test1 {
    public static double getResult(int money){
        double result = 0;
        if(money < 5000){
            result = 0;
        }else if(money < 8000){
            result += (money - 5000) * 0.03;
        }else if(money < 17000){
            result += ((money - 8000) * 0.10
                    + 3000 * 0.03);
        }else if(money < 30000){
            result += ((money - 17000) * 0.20
                    + 3000 * 0.03
                    + 9000 * 0.10);
        }else if(money < 40000){
            result += ((money - 30000) * 0.25
                    + 3000 * 0.03
                    + 9000 * 0.10
                    + 13000 * 0.20);
        }else if(money < 60000){
            result += ((money - 40000) * 0.30
                    + 3000 * 0.03
                    + 9000 * 0.10
                    + 13000 * 0.20
                    + 10000 * 0.25);
        }else if(money < 85000){
            result += ((money - 60000) * 0.35
                    + 3000 * 0.03
                    + 9000 * 0.10
                    + 13000 * 0.20
                    + 10000 * 0.25
                    + 20000 * 0.30);
        }else{
            result += ((money - 85000) * 0.45
                    + 3000 * 0.03
                    + 9000 * 0.10
                    + 13000 * 0.20
                    + 10000 * 0.25
                    + 20000 * 0.30
                    + 25000 * 0.35);
        }
        return result;
    }
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int i = 0;
        int[] nums = new int[n];
        double[] result = new double[n];
        while (i < n){
            nums[i++] = scanner.nextInt();
        }
        for (i = 0; i < n; i++){
            result[i] = getResult(nums[i]);
        }
        for (double j:
                result){
            System.out.println(Math.round(j));
        }
    }
}

通过率100%,这个太水了


第二题


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

public class Test2 {
    public static List<String> special_words_list =
            new ArrayList<>();
    static {
        special_words_list.add("password");
        special_words_list.add("admin");
        special_words_list.add("qwerty");
        special_words_list.add("hello");
        special_words_list.add("iloveyou");
        special_words_list.add("112233");
    }
    public static String special_char = "!@#$%^&*()_+[]{},.<>/?";
    public static final String yes = "yes";
    public static final String no = "no";

    public static String getBool(boolean b){
        return b?yes:no;
    }

    public static String validatePassword(String password){
//        boolean validate_length = true;
//        boolean validate_char = true;
        boolean hascontinue_char = false;
        boolean hascontinue_digit = false;
        boolean hasspecial_words = false;
        boolean hasDigits = false;
        boolean hasUp = false;
        boolean hasLow = false;
        boolean hasSpChar = false;

        //1
        if (password.length() < 8){
            return no;
        }

        char c;
        for (int i = 0; i < password.length(); i++){
            //2
            c = password.charAt(i);
            if (Character.isDigit(c)){
                //3
                if (i > 0 && i < (password.length() - 1)){
                    if ((c - (password.charAt(i - 1)) ==
                            ( password.charAt(i + 1) - c))){
                        //包括等差
                        hascontinue_digit = true;
                    }
                }
                hasDigits = true;
            }else if (Character.isUpperCase(c)){
                //4
                if (i > 0 && i < (password.length() - 1)){
                    if ((c - password.charAt(i - 1)) ==
                            (password.charAt(i + 1) - c)){
                        //包括连续字母
                        hascontinue_char = true;
                    }
                }
                hasUp = true;
            }else if(Character.isLowerCase(c)){
                //4
                if (i > 0 && i < (password.length() - 1)){
                    if (c != password.charAt(i - 1) &&(c - password.charAt(i - 1)) ==
                            (password.charAt(i + 1) - c)){
                        //包括连续字母
                        hascontinue_char = true;
                    }
                }
                hasLow = true;
            }else if(special_char.indexOf(c) != -1){
                hasSpChar = true;
            }

        }

        for (String sp:
                special_words_list){
            if(password.indexOf(sp) != -1){
                hasspecial_words = true;
            }
        }

        if (!hasspecial_words
                && !hascontinue_char
                && !hascontinue_digit
                && hasDigits
                && hasLow
                && hasUp
                && hasSpChar){
            return yes;

        }else {
            return no;
        }


    }

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        String[] password = new String[n];
        String[] result = new String[n];
        int i = 0;
        while (i < n){
            password[i++] = scanner.next();
        }
        for (i = 0; i< n; i++){
            result[i] = validatePassword(password[i]);
        }
        for (String re
                : result){
            System.out.println(re);
        }

    }
}

30?40?60?忘了

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 2018年元月3号下午,迎来了入冬以来的第一场雪,一直下。 第二天早上醒来的时候,拉开窗帘,外面是一个白...
    惠顾星辰阅读 352评论 14 9
  • 上文中介绍了如何使用redis实现用户的注册,以及登陆的在线状态保持。而使用redis另外常见的应用,还有好友列表...
    selbstkennen梁晨阅读 3,043评论 0 6
  • 因为懂得,所以珍惜。 和才女张爱玲所说的并不一致,我今天想要表达的,是珍惜。 不得不承认的是,我们的世界复杂又多元...
    小猴herher阅读 172评论 0 1
  • 穿过一大片雨水刚刚冲刷过的农田,停在被岁月摧残过几近斑驳的桥头,随拍,一股小小的思绪涌上心头 面前的这条河水一直往...
    a437f2afd094阅读 147评论 0 0