Algorithm(218)
-
[Boj]1919: 애너그램 만들기
1. problem : https://www.acmicpc.net/problem/1919 2. solution 1 :#include using namespace std;int main(void) { ios::sync_with_stdio(0); cin.tie(0); int a[26] = {}; string str1, str2; cin >> str1 >> str2; for (auto c : str1) a[c - 'a']++; for (auto c : str2) a[c - 'a']--; int ans = 0; for (int i : a) { ans += abs(i); } cout
2024.08.04 -
[Boj]11326:Strfry
1. problem : https://www.acmicpc.net/problem/11328 2. solution 1 :#include using namespace std;int main(void) { ios::sync_with_stdio(0); cin.tie(0); int N; cin >> N; while (N--) { int a[26] = {}; string s1, s2; cin >> s1 >> s2; for (auto c : s1) a[c - 'a']++; for (auto c : s2) a[c - 'a']--; bool isPossible = true; for (int i : a) { if (i != 0) { isPossible = false; } } if (isP..
2024.08.04 -
[Boj] 10807번 : 개수 세기
1. problem :https://www.acmicpc.net/problem/10807 2. solution 1 :# 입력 받기N = int(input()) # 정수의 개수nums = list(map(int, input().split())) # 정수 리스트target = int(input()) # 찾으려는 정수# target의 개수 세기count = nums.count(target)# 결과 출력print(count)
2024.08.04 -
[Boj]3273번 : 두 수의 합
1. problem :https://www.acmicpc.net/problem/3273 2. solution 1 :def count_pairs_with_sum(arr, x): arr.sort() left = 0 right = len(arr) - 1 count = 0 while left two-pointer를 이용한 방법. 3. solution 2 :n = int(input())nums = list(map(int,input().split()))x = int(input())count = 0 hashMap = {}for i in range(n): target = x - nums[i] if target in hashMap: if hashMap[targ..
2024.08.04 -
[Boj]1475 :방 번호
1. problem : https://www.acmicpc.net/problem/1475 2. solution 1 :def calculate_min_sets(room_number: str) -> int: counts = [0] * 10 for digit in room_number: counts[int(digit)] += 1 counts[6] = (counts[6] + counts[9] + 1) // 2 counts[9] = counts[6] # 9는 더 이상 개별적으로 고려하지 않음 return max(counts[:9]) # counts[9]는 이미 6과 통합되어 있으므로, 0~8까지만 고려# 테스트room_number = input()...
2024.08.04 -
[Leetcode]981. Time Based Key-Value Store
1. problem :https://leetcode.com/problems/time-based-key-value-store/ 2. solution 1 :from collections import defaultdictclass TimeMap: def __init__(self): self.timeDs = defaultdict(list) def set(self, key: str, value: str, timestamp: int) -> None: self.timeDs[key].append((timestamp, value)) def get(self, key: str, timestamp: int) -> str: if key not in self.timeDs or..
2024.08.03