반응형
풀이
시작시 컵홀더의 초기값은 1, 이후 S는 한개당 1, LL은 두개당 1을 카운트하므로 S의 값은 1, LL의 값은 0.5로 계산한다.
자바
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
String seats = br.readLine();
float cnt = 1;
for (int i = 0; i < seats.length(); i++) {
seats.charAt(i);
if (seats.charAt(i) == 'S')
cnt += 1;
else if (seats.charAt(i) == 'L')
cnt += 0.5;
}
if (cnt < n)
System.out.print((int)cnt);
else
System.out.print(n);
}
}
파이썬
n = int(input())
seats = str(input())
arr = [1, 0.5]
type = ['S', 'L']
cnt = 1
for seat in seats:
for i in range(len(type)):
if seat == type[i]:
cnt += arr[i]
if cnt < n:
print(int(cnt))
else:
print(n)
'백준' 카테고리의 다른 글
1546번: 평균 (0) | 2022.02.15 |
---|---|
1110번: 더하기 사이클 (0) | 2022.02.15 |
11399번: ATM (0) | 2022.02.14 |
1931번: 회의실 배정 (0) | 2022.02.14 |
11047번: 동전 0 (0) | 2022.02.14 |