본문 바로가기

Algorithm/Brute Force

(118)
(C++) - LeetCode (easy) 1072. Flip Columns For Maximum Number of Equal Rows https://leetcode.com/problems/greatest-common-divisor-of-strings/description/ Greatest Common Divisor of Strings - LeetCode Greatest Common Divisor of Strings - For two strings s and t, we say "t divides s" if and only if s = t + ... + t (i.e., t is concatenated with itself one or more times). Given two strings str1 and str2, return the largest string x such that x divides both leetcode.com 전수조사..
(C++) - LeetCode (easy) 268. Missing Number https://leetcode.com/problems/missing-number/description/ Missing Number - LeetCode Missing Number - Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array. Example 1: Input: nums = [3,0,1] Output: 2 Explanation: n = 3 since there are 3 numbers, so all n leetcode.com 전수조사 문제였습니다. 📕 풀이방법 📔 풀이과정 1. nums의 원소들을 map m에..
(C++) - LeetCode (easy) 27. Remove Element https://leetcode.com/problems/remove-element/ Remove Element - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 간단 전수조사 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 n이 작기 때문에 2차원 loop를 수행해 정렬해도 됩니다. 📔 풀이과정 지울 수를 배열의 뒷편에 배치시키는 swap문제라고 생각해봅니다. 앞의 val이 있다면 그 이후부터 for loop를 수행하며 val이 아닌 원소를 찾아 swap을 해주면 ..
(C++) - LeetCode (easy) 14. Longest Common Prefix https://leetcode.com/problems/longest-common-prefix/ Longest Common Prefix - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 전수조사 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 strs를 문자열의 길이가 짧은 순으로 정렬해줍니다. 정답을 반환할 ans를 선언해줍니다. 📔 풀이과정 strs[0]이 가장 짧은 문자열이므로 이 size만큼이 최대 prefix입니다. 이에 대해 for loop를 수행합니다...
(C++, Rust) - 백준(BOJ) 13225 : Divisors https://www.acmicpc.net/problem/13225 13225번: Divisors For each integer n, print a line with the number n itself, a space and the number of divisors. www.acmicpc.net 전수조사 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 test case 개수 n, 매 test case마다 숫자 num을 선언 후 입력받습니다. vector divisors 📔 풀이과정 1 ~ n까지 loop를 수행하며 인수를 vector에 저장해줍니다. 📔 정답출력 num과 divisors의 길이를 출력해줍니다. 📕 Code C++ #include using namespace std; int n, num; i..
(Rust) - 백준(BOJ) 23348 : 스트릿 코딩 파이터 https://www.acmicpc.net/problem/23348 23348번: 스트릿 코딩 파이터 첫째 줄에 세 가지 기술의 난이도 $A$, $B$, $C$가 '한손 코딩', '노룩 코딩', '폰코딩' 순서대로 공백을 사이에 두고 주어진다. ($0 \le A, B, C \le 1,000$) 둘째 줄에 참가한 동아리의 수 $N$이 주어진다. ($1 www.acmicpc.net 전수조사 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 점수정보와 동아리 정보, 각 동아리원의 기술 사용정보를 scores, club_numbers, tech_freq에 선언 후 저장합니다. 📔 풀이과정 각 동아리당 사용정보를 score에 누적해 저장합니다. 매 동아리당 최대 점수를 ans와 비교해 저장합니다. 📔 정답출력 ans..
(Rust) - 백준(BOJ) 25494 : 단순한 문제 (Small) https://www.acmicpc.net/problem/25494 25494번: 단순한 문제 (Small) 세 양의 정수 $a$, $b$, $c$가 주어질 때, 다음 조건을 만족하는 정수 쌍 $(x, y, z)$의 개수를 구하시오. $1 \le x \le a$ $1 \le y \le b$ $1 \le z \le c$ $(x\,\bmod\,y) = (y\,\bmod\,z) = (z\,\bmod\,x)$ $(A\,\bmod\,B)$는 $A$를 $B$ www.acmicpc.net 전수조사 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 매 줄을 입력받을 line을 선언한 후 test_case에 parse한 결과를 저장합니다. 이 후 매 test_case마다 a,b,c정보를 저장합니다. 📔 풀이과정 조건에 맞는..
(C++) - 백준(BOJ) 7490 : 0 만들기 https://www.acmicpc.net/problem/7490 7490번: 0 만들기 각 테스트 케이스에 대해 ASCII 순서에 따라 결과가 0이 되는 모든 수식을 출력한다. 각 테스트 케이스의 결과는 한 줄을 띄워 구분한다. www.acmicpc.net 전수조사 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 test case 수 t, 제한 n을 입력받습니다. 📔 풀이과정 두 가지 일에 대해 구현하면 됩니다.1. n까지 수를 오름차순으로 뽑기2. 뽑은 수의 값 계산하기 📔 정답출력 뽑은 수의 식 계산 결과가 0이면 수식을 출력합니다. 📕 Code #include using namespace std; int t, n; int getEval(string s){ string tmpS, tmpNum; for..