20250710 baekjoon

This commit is contained in:
songyc macbook 2025-07-10 20:32:47 +09:00
parent 46fd6cf36d
commit efbb3349c0
2 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1,41 @@
import java.util.*;
public class _2108{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int[] arr = new int[N];
int sum=0;
for(int i=0; i<N; i++){
arr[i] = sc.nextInt();
sum += arr[i];
}
Arrays.sort(arr);
int average = (int)Math.round((double)sum/N);
Map<Integer, Integer> map = new HashMap<>();
int maxFreqCount = 0;
int maxFreqVal=0;
for(int num : arr){
int count = map.getOrDefault(num, 0) + 1;
if(count>maxFreqCount){
maxFreqCount = count;
maxFreqVal = num;
}
map.put(num, count);
}
List<Integer> maxFreq = new ArrayList<>();
for(Map.Entry<Integer, Integer> entry : map.entrySet()){
if(entry.getValue() == maxFreqCount) maxFreq.add(entry.getKey());
}
if(maxFreq.size()>1) {
maxFreq.sort((a,b)->a-b);
maxFreqVal = maxFreq.get(1);
}
System.out.printf("%d\n%d\n%d\n%d\n",average, arr[N/2], maxFreqVal, arr[N-1]-arr[0]);
sc.close();
}
}

View File

@ -0,0 +1,21 @@
n = int(input())
sequence = [int(input()) for _ in range(n)]
stack = []
operator = []
idx_seq = 0
idx_num = 1
while idx_seq < n :
if stack and stack[-1] == sequence[idx_seq] :
operator.append('-')
stack.pop()
idx_seq += 1
else :
if idx_num > n :
print("NO")
break
operator.append('+')
stack.append(idx_num)
idx_num += 1
else :
print('\n'.join(operator))