题解 | #密码检查#

逃脱神凛幻域

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;
        }
    }
}

}

全部评论

相关推荐

牛客868257804号:九个中铁八个中建
点赞 评论 收藏
分享
Hello_WordN:咱就是说,除了生命其他都是小事,希望面试官平安,希望各位平时也多注意安全
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务