forked from CBNU-Nnet/2022-algorithm-study
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[3주차] : 허원일 - 5883 아이폰 9S Silver4 (CBNU-Nnet#60)
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
N = int(input()) | ||
line = [] # 줄 정보 | ||
long_seq = [] | ||
|
||
# 최대길이를 계산하는 함수 | ||
def max_seq_cap(line): | ||
max_count = 1 | ||
count = 1 | ||
for i in range(0, len(line)-1): | ||
if line[i] == line[i+1]: # 연속된 두 원소가 같으면 count 증가 | ||
count += 1 | ||
else: # 다르면 max_count 초기화 | ||
max_count = max(count, max_count) | ||
count = 1 # count 초기화 | ||
return max(count, max_count) # 예외처리 - new_line이 한 용량으로만 이루어진 경우 | ||
|
||
for _ in range(N): | ||
cap = int(input()) | ||
line.append(cap) | ||
set = set(line) # 줄에 있는 구매자들이 원하는 용량종류를 담는 집합 | ||
|
||
for element in set: | ||
new_line = line.copy() # line을 복사해 new_line을 생성 | ||
while element in new_line: # 특정 용량을 원하는 사람을 모두 뺌 | ||
new_line.remove(element) | ||
long_seq.append(max_seq_cap(new_line)) | ||
|
||
print(max(long_seq)) |