| 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 | 
| 9 | 10 | 11 | 12 | 13 | 14 | 15 | 
| 16 | 17 | 18 | 19 | 20 | 21 | 22 | 
| 23 | 24 | 25 | 26 | 27 | 28 | 29 | 
| 30 | 
                                        Tags
                                        
                                    
                                        
                                    - data_structure
 - Numpy
 - 피보나치 수
 - Counting cells in a blob
 - flask
 - All Longest Strings
 - 2015 봄학기 알고리즘
 - codesingal
 - baekjun
 - cpp
 - almostIncreasingSequence
 - matrixElementsSum
 - 2750
 - 백준
 - Sequential Search
 - Daily Commit
 - shapeArea
 - codesignal
 - 수 정렬하기
 - Python
 - 파이썬 포렌식
 - til
 - C++
 - centuryFromYear
 - recursion
 - 파이썬머신러닝완벽가이드
 - collections.deque
 - 10953
 - adjacentElementsProduct
 - markdown
 
                                        Archives
                                        
                                    
                                        
                                    - Today
 
- Total
 
Introfor
[백준] 1316번 그룹 단어 체커 본문
바로 나오는 단어를 통해 정렬한 단어가 입력 받은 단어와 같은지 비교해서 풀었는데.. 찾아보니 이렇게 푼 사람들이 많았다
| 
 1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
 | 
 def solution(): 
    res_ = 0 
    for i in range(int(input())): 
        word = input() 
        if list(word) == sorted(word, key=word.find): 
            res_ += 1 
    return res_ 
res = solution() 
print(res) 
 | 
cs | 
이 방법 말고 다른 방법을 생각해봐야겠다.
다른 코드
너무 단순하게만 생각했던 것 같다. 누구나 쉽게 단어의 한 알파벳과 그 다음 알파벳을 비교하는 방식으로 생각하기 쉽다. 하지만 이 방식과 다르게 아닌 경우가 발생하는 경우 그 단어를 카운트에서 제외하는 방식이다.
예를 들어, aaacccbbba는 마지막 알파벳 a에 의해 그룹단어가 되지 않는다. 이것을 str.find()를 이용하면, 소소코드에서 word.find('b')는 6을 반환하고 word.find('a')은 0을 반환한다. 그러면 마지막 알파벳 a에서 word.find('a') 했을 때 word.find('b')보다 작다는 것은 단어 앞에 알파벳 a가 존재한다는 의미다.
| 
 1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
 | 
 def solution(): 
    res = int(input()) 
    for _ in range(res): 
        word = input() 
        for i in range(1, len(word)): 
            if word.find(word[i-1]) > word.find(word[i]): 
                res -= 1 
                break 
    return res 
res = solution() 
print(res) 
 | 
cs | 
'Programming_prob > BaekJoon' 카테고리의 다른 글
| [백준] 2839번 설탕 배달 (0) | 2020.10.09 | 
|---|---|
| [백준] 1712번 손익분기점 (0) | 2020.10.08 | 
| [백준] 2941번 크로아티아 알파벳 (0) | 2020.10.07 | 
| [백준] 2908번 상수 (0) | 2020.10.06 | 
| [백준] 1152번 단어의 개수 (0) | 2020.10.06 | 
                          Comments