题解 | #密码检查#
逃脱神凛幻域
http://www.nowcoder.com/practice/037dc00d6e3442f185cf4cde359ba460
import java.util.Scanner;
public class Main{
public static int minPhysicalPower = 0;
public static String stepScheme = "";
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T = Integer.parseInt(in.nextLine());
for(int i1=0; i1<T; i1++){
int n = Integer.parseInt(in.nextLine());
String[] EArr = in.nextLine().split(" ");
int[] E = new int[n];
for(int i2=0; i2<n; i2++){
E[i2] = Integer.parseInt(EArr[i2]);
}
String[] SArr = in.nextLine().split(" ");
int[] S = new int[n];
for(int i2=0; i2<n; i2++){
S[i2] = Integer.parseInt(SArr[i2]);
}
String[] WArr = in.nextLine().split(" ");
int[] W = new int[n];
for(int i2=0; i2<n; i2++){
W[i2] = Integer.parseInt(WArr[i2]);
}
String[] NArr = in.nextLine().split(" ");
int[] N = new int[n];
for(int i2=0; i2<n; i2++){
N[i2] = Integer.parseInt(NArr[i2]);
}
escapseDomain(n, E, S, W, N);
System.out.println(minPhysicalPower);
System.out.println(stepScheme);
minPhysicalPower = 0;
stepScheme = "";
}
}
public static void escapseDomain(int n, int[] E, int[] S, int[] W, int[] N){
for(int i=0; i<n; i++){
if( E[i]<=S[i] && E[i]<=W[i] && E[i]<=N[i] ){
minPhysicalPower+=E[i];
stepScheme+="E";
continue;
}
if( S[i]<=E[i] && S[i]<=W[i] && S[i]<=N[i] ){
minPhysicalPower+=S[i];
stepScheme+="S";
continue;
}
if( W[i]<=E[i] && W[i]<=S[i] && W[i]<=N[i] ){
minPhysicalPower+=W[i];
stepScheme+="W";
continue;
}
if( N[i]<=E[i] && N[i]<=S[i] && N[i]<=W[i] ){
minPhysicalPower+=N[i];
stepScheme+="N";
continue;
}
}
}}
查看29道真题和解析