网易第一题:
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?忘了