[TIL] 정글 97일차 - 나만의 무기

신승준·2022년 7월 4일
0

알고리즘

프로그래머스

  • Level 2
    • 뉴스 클러스터링
      • 단순 구현 문제인 것 같다.
from collections import Counter

def solution(str1, str2):
    str1_alpha = list()
    str2_alpha = list()
    
    for i in range(len(str1) - 1):
        if (str1[i:i + 2].lower()).isalpha():
            str1_alpha.append(str1[i:i + 2].lower())
            
    for i in range(len(str2) - 1):
        if (str2[i:i + 2].lower()).isalpha():
            str2_alpha.append(str2[i:i + 2].lower())
            
    str1_counter = Counter(str1_alpha)
    str2_counter = Counter(str2_alpha)
    
    def _intersection(a, b):
        result = 0
        
        temp_a = a.keys()
        temp_b = b.keys()
        
        for key in temp_a:
            if key in temp_b:
                result += min(a[key], b[key])
                
        return result
    
    def _union(a, b):
        result = 0
        
        temp_a = a.keys()
        temp_b = b.keys()
        
        for key in temp_a:
            if key in temp_b:
                result += max(a[key], b[key])
                
            else:
                result += a[key]
                
        for key in temp_b:
            if key in temp_a:
                continue
            
            else:
                result += b[key]
                
        return result
    
    intersection = _intersection(str1_counter, str2_counter)
    union = _union(str1_counter, str2_counter)
    
    if intersection == 0 and union == 0:
        return 65536
    
    else:
        return int((intersection / union) * 65536)    

백준

  • 수학
      1. 숫자의 합
n = int(input())
nums = str(input())
result = 0

for num in nums:
    result += int(num)
    
print(result)
  • 수학
      1. 한수
import sys
sys.stdin = open('input.txt')
input = sys.stdin.readline

n = int(input())
result = 0

def check(num):
    num = str(num)
    
    if len(num) <= 2:
        return True
        
    else:
        for i in range(len(num) - 2):
            if int(num[i]) - int(num[i + 1]) != int(num[i + 1]) - int(num[i + 2]):
                return False
    
    return True
        

for num in range(1, n + 1):
    if check(num):
        result += 1
        
print(result)

Figma

궁금한 점

하루를 마치고

profile
메타몽 닮음 :) email: alohajune22@gmail.com

0개의 댓글