• Home
  • About
    • JOOS photo

      JOOS

      Joos's blog

    • Learn More
    • Email
    • Github
  • Posts
    • All Posts
    • All Tags
  • Projects

1204. [S/W 문제해결 기본] 1일차 - 최빈수 구하기

10 Dec 2018

Reading time ~1 minute

문제: https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV13zo1KAAACFAYh&categoryId=AV13zo1KAAACFAYh&categoryType=CODE

import java.util.*;

public class Solution {
    private static final Scanner sc = new Scanner(System.in);

    public static void main(String args[]) {
        for(int t=1; t <= 10; t++){
            int n = sc.nextInt();
            int[] l = new int[n+1];
            for (int i=0; i<n; i++) {
                l[i] = sc.nextInt();
            }

            int ans = 0;
            int[] tmp = new int[6];
            for(int i =0; i< l.length-5; i++){
                int maxL = 0;
                for(int j =0; j < 5; j++){
                    tmp[j] = l[i+j];
                    if( maxL < l[i+j] ){
                        maxL = l[i+j];
                    }
                }
                if( maxL == tmp[2] ){
                    int stnd = tmp[2];
                    tmp[2] = 0;
                    maxL = 0;
                    for(int j =0; j < 5; j++){
                        if( maxL < tmp[j] ){
                            maxL = tmp[j];
                        }
                    }
                    int tmp_max = stnd - maxL;
                    ans += tmp_max;
                }

            }
            System.out.println("#"+t +" "+ans);


        }



    }
}


algorithmjavasamsung Share Tweet +1