본문 바로가기

Algorithm/String

(92)
(C++) - LeetCode (easy) 345. Reverse Vowels of a String https://leetcode.com/problems/reverse-vowels-of-a-string/description/ Reverse Vowels of a String - LeetCode Can you solve this real interview question? Reverse Vowels of a String - Given a string s, reverse only all the vowels in the string and return it. The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in both lower and upper cases, more than onc leetcode.com 문자열 구현 문제였습니다. 📕 풀이방..
(C++) - LeetCode (easy) 344. Reverse String https://leetcode.com/problems/reverse-string/description/ Reverse String - LeetCode Reverse String - Write a function that reverses a string. The input string is given as an array of characters s. You must do this by modifying the input array in-place [https://en.wikipedia.org/wiki/In-place_algorithm] with O(1) extra memory. Example 1: leetcode.com 문자열 관련 함수 reverse를 사용해보는 문제였습니다. 📕 풀이방법 📔 풀이과정 ..
(C++) - LeetCode (easy) 290. Word Pattern https://leetcode.com/problems/word-pattern/description/ 1) return false; vector v = split(s, ' '); if(pattern.size() != v.size()) return false; map m; map m2; for(int i = 0; i < v.size(); i++) { if(m2.count(pattern[i])) continue; m[v[i]] = pattern[i]; m2[pattern[i]] = v[i]; } for(int i = 0; i < v.size(); i++) { if(m[v[i]] != pattern[i]) { return false; } } return true; } }; *더 나은 내용을 위한 지적, 조언은 ..
(C++) - LeetCode (easy) 125. Valid Palindrome https://leetcode.com/problems/valid-palindrome/ Valid Palindrome - 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 문자열을 다루는 문제였습니다. 📕 풀이방법 📔 풀이과정 공백을 제거하고 대문자면 소문자로 변형해 숫자와 소문자 alphabat만 남기는 getTrimedString함수를 수행해 걸러진 문자열을 s에 저장합니다. 📔 정답출력 문자열 길이의 절반까지만 for loop를 수행해 양 옆이 다르다면 fals..
(C++) - LeetCode (easy) 58. Length of Last Word https://leetcode.com/problems/length-of-last-word/ Length of Last Word - 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 간단한 문자열 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 1. stringstream " "단위로 split해주는 함수를 구현해줍니다. 2. 이후 " "로 구분된 문자열을 vector v를 선언해 함수의 반환값으로 저장합니다.3. 정답 지역 변수 length를 선언해 0으로 초기화합니..
(C++, Rust) - 백준(BOJ) 23303 : 이 문제는 D2 입니다. https://www.acmicpc.net/problem/23303 23303번: 이 문제는 D2 입니다. 문자열 안에 $D2$나 $d2$가 들어있다면 D2를 출력한다. 두 글자는 반드시 붙어있어야 하며, $D$/$d$와 $2$ 사이에 공백이 있어도 안 된다. 만약 문자열 안에 해당 문자가 없다면 unrated를 출력한다. www.acmicpc.net 문자열을 찾는 find함수를 써보는 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 한줄 s를 선언 후 입력받습니다. 📔 정답출력 find함수의 결과값이 유의미 할 때 D2를, 하지 않을 때 unrated를 정답으로 출력합니다 📕 Code C++ #include using namespace std; string s; int main(){ getline(cin..
백준(BOJ) 4740 : 거울, 오! 거울 https://www.acmicpc.net/problem/4740 4740번: 거울, 오! 거울 하나 또는 그 이상의 줄에 각각 ASCII 글자로 나타낼 수 있는 단어들(알파벳, 숫자, 공백, 구두점 등)로 구성된 문장을 입력한다. 각 문장은 최소 1글자에서 최대 80글자로 이루어져 있으며, ***을 www.acmicpc.net 문자열을 다뤄보는 간단한 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 문자열 변수를 선언 후 입력받습니다. 📔 정답출력 문자열을 뒤집는 함수를 수행 후 출력합니다. 📕 Code 📔 C++ #include using namespace std; string s; int main(){ while(1){ getline(cin,s); if(s == "***") break; reverse..
(C++) - 백준(BOJ) 21964 : 선린인터넷고등학교 교가 https://www.acmicpc.net/problem/21964 21964번: 선린인터넷고등학교 교가 알파벳 대문자, 알파벳 소문자, 쉼표, 마침표의 아스키 코드는 각각 65-90, 97-122, 44, 46이다. www.acmicpc.net 간단한 문자열 slicing 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 문자열의 길이 n, 문자열 s를 선언 후 입력받습니다. 📔 정답출력 마지막 5글자를 substr함수를 이용해 출력합니다. 📕 Code #include using namespace std; int n; string s; int main(){ cin >> n >> s; cout