알고리즘(python)/문자열
[Python]문자열 백준 1316
개발일기
2019. 12. 19. 11:29
반응형
문제
https://www.acmicpc.net/problem/1316
연속하지않고 이전에 나왔으면 그룹단어가 아닌것이다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | import sys n=int(sys.stdin.readline().strip()) result=n #초기화 조건에 걸리면 빼주는 방식으로 while(n>0): n-=1 continue_check = '' #연속하는지 체크 group_word = [0 for _ in range(26)] #앞에 나왔는지 체크 s=list(sys.stdin.readline().strip()) for i in s: if continue_check==i: #연속되면 넘어감 continue if group_word[ord(i)-97]==1 and continue_check!=i: #앞에 나오고 연속된 값이 아니라면 1을빼준다 result-=1 break continue_check=i #다음 문자와 연속하는지 비교할값 저장 group_word[ord(i)-97]=1 #이번에 나온 문자 체크 print(result) | cs |
반응형