백준 2810번 (bronze 1)
import java.util.Scanner;
public class problem39 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int size = in.nextInt();
String cup = in.next();
// 시작 할때 왼쪽에는 무조건 컵홀더가 있다.
int count = 1;
for (int i = 0; i < size; i++) {
char a = cup.charAt(i);
if(a == 'S'){
count++;
} else if (a == 'L') {
// L은 커플임으로 LL 두개가 입력된다.
i++;
count++;
}
}
if(count > size){
System.out.println(size);
}else {
System.out.println(count);
}
}
}
백준 2846번 (bronze 1)
import java.util.Scanner;
public class problem40 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int size = in.nextInt();
int [] array = new int[size];
int total = 0;
for (int i = 0; i < size; i++) {
array[i] = in.nextInt();
}
int temp = 0;
for (int i = 0; i < size - 1; i++) {
// 오르막길임으로 array[i+1]의 값이 크면 계산
if(array[i+1] > array[i]){
total+= array[i+1] - array[i];
}else{
total = 0;
}
// 크기 비교가 끝나면 temp값에 정답을 담는다.
temp = Math.max(total, temp);
}
System.out.println(temp);
}
}
백준 2851번 (bronze 1)
import java.util.Scanner;
public class problem41 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int[] array = new int[10];
int count = 0;
for (int i = 0; i < array.length; i++) {
array[i] = in.nextInt();
}
int max = 0;
int temp = 100;
for (int i = 0; i < array.length; i++) {
count += array[i];
// 버섯을 먹는거를 멈추는게 아니라 10개 다먹는다고 시나리오를 잡는다.
// Math.abs() 절대값
if (Math.abs(100 - count) <= temp) {
temp = Math.abs(100 - count);
max = count;
}
}
System.out.println(max);
}
}