Doldoi's blog

고정 헤더 영역

글 제목

메뉴 레이어

Doldoi's blog

메뉴 리스트

  • 홈
  • 분류 전체보기
    • C++
    • Chem
    • Python

검색 레이어

Doldoi's blog

검색 영역

컨텐츠 검색

백준

  • [Python/파이썬] 백준 #1181 단어 정렬

    2025.03.26 by Doldoi

  • [Python/파이썬] 백준 #1157 단어 공부

    2025.03.22 by Doldoi

[Python/파이썬] 백준 #1181 단어 정렬

문제 링크: https://www.acmicpc.net/problem/1181문제 문자열을 정렬하고 중복을 제거하는 문제이다.코드n = int(input())li = [input().strip() for _ in range(n)]li = list(set(li))li.sort(key=lambda x: (len(x), x))print('\n'.join(li))  입력받은 문자열을 strip()으로 한 글자씩 리스트에 저장하고set()으로 중복 제거lambda를 써서 정렬 기준을 정한 후, sort 함수로 정렬 시간 복잡도입력 부분: O(n$\times$m)    $\leftarrow$    m 은 각 단어의 평균 길이set() 변환: O(n)list() 변환: O(n)정렬 과정: Python의 sort()는..

Python 2025. 3. 26. 21:24

[Python/파이썬] 백준 #1157 단어 공부

문제 링크: https://www.acmicpc.net/problem/1157 문제 코드words = list(input().upper())li = list(set(words))count_list = []for x in li: c = words.count(x) count_list.append(c)if count_list.count(max(count_list)) > 1: print("?")else: max_index = count_list.index(max(count_list)) print(li[max_index]) upper()를 사용하여 입력받은 문자를 대문자로 변환하고 words에 리스트로 저장set()으로 words의 중복을 제거 후 다시 리스트로 li에 저장for문으로 ..

Python 2025. 3. 22. 03:11

추가 정보

인기글

최신글

페이징

이전
1
다음
TISTORY
Doldoi's blog
페이스북 트위터 인스타그램 유투브 메일

티스토리툴바