ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 1316 파이썬 백준
    개발/알고리즘(백준) 2022. 8. 24. 13:10

    정답코드

    n = int(input())
    
    group_word = 0
    for _ in range(n):
        word = input()
        error = 0
        for index in range(len(word)-1):  # 인덱스 범위 생성 : 0부터 단어개수 -1까지 
            if word[index] != word[index+1]:  # 연달은 두 문자가 다른 때,
                new_word = word[index+1:]  # 현재글자 이후 문자열을 새로운 단어로 생성
                if new_word.count(word[index]) > 0:  # 남은 문자열에서 현재글자가 있있다면
                    error += 1  # error에 1씩 증가.
        if error == 0:  
            group_word += 1  # error가 0이면 그룹단어
    print(group_word)

    내코드

    n = int(input())
    
    for _ in range(n):
        word = input()
        lst = []
        for i in range(len(word)-1):
            if word[i+1] != word[i]:
                lst.append(word[i])
            else:
                continue
        lst.append(word[-1])
        lst2 = []
        for x in lst:
            if lst.count(x) >= 2:
                break
            elif lst.count(x) == 1:
                lst2.append(word)
    print(len(lst2))​
    N = int(input())
    cnt = N
    
    for i in range(N):
        word = input()
        for j in range(0, len(word)-1):
            if word[j] == word[j+1]:
                pass
            elif word[j] in word[j+1:]:
                cnt -= 1
                break
    
    print(cnt)

    '개발 > 알고리즘(백준)' 카테고리의 다른 글

    백준 2292 python  (0) 2022.08.24
    파이썬 1712  (0) 2022.08.24
    백준 2941 크로아티아 알파벳 python  (0) 2022.08.24
    백준 5622번 파이썬  (0) 2022.08.24
    백준 2908  (0) 2022.08.23
Designed by Tistory.