본문 바로가기

Algorithm/String

(93)
(C++) - 백준(BOJ) 12518번 : Centauri Prime (Small2) https://www.acmicpc.net/problem/12518 12518번: Centauri Prime (Small2) Back in the old days before the creation of the mighty Centauri Republic, the planet Centauri Prime was split into several independent kingdoms. The kingdom of Mollaristan was ruled by king Loatold, while the kingdom of Auritania was under the rule of quee www.acmicpc.net 문자열 다루는 문제였습니다. * 나라이름이 최대 100글자이므로 1글자인 나라의 경우 대문자이자 마..
(C++) - 백준(BOJ) 12517번 : Centauri Prime (Small1) https://www.acmicpc.net/problem/12517 12517번: Centauri Prime (Small1) Back in the old days before the creation of the mighty Centauri Republic, the planet Centauri Prime was split into several independent kingdoms. The kingdom of Mollaristan was ruled by king Loatold, while the kingdom of Auritania was under the rule of quee www.acmicpc.net 단순 string 문제였습니다. * a 유무 조심 📕 Code #include using names..
(C++) - 백준(BOJ) 8545번 : Zadanie próbne https://www.acmicpc.net/problem/8545 8545번: Zadanie próbne Napisz program, który odwraca podane słowo trzyliterowe. www.acmicpc.net 눈치껏(?) 문자열 문제였습니다. 📕 Code #include using namespace std; string s; int main(){ cin >> s; for(int i = s.size() - 1; i >= 0; i--) cout
(C++) - 백준(BOJ) 11117번 : Letter Cookies https://www.acmicpc.net/problem/11117 11117번: Letter Cookies The first line of the input consists of a single number T, the number of letter cookie boxes your sister has. Each test case starts with a line describing all the letters in this box, in no particular order. Then follows a line with W, the number of words www.acmicpc.net 문제 지문해석이 헷갈렸던 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 가장 처음에 입력받는 것이 테스트 케이스입니다..
(C++) - 백준(BOJ) 4889번 : 안정적인 문자열 https://www.acmicpc.net/problem/4889 4889번: 안정적인 문자열 입력은 여러 개의 데이터 세트로 이루어져 있다. 각 데이터 세트는 한 줄로 이루어져 있다. 줄에는 여는 괄호와 닫는 괄호만으로 이루어진 문자열이 주어진다. 문자열의 길이가 2000을 넘는 경우 www.acmicpc.net 문자열을 다루는 문제였습니다. 📕 풀이방법 문자열의 길이가 2000이므로 재귀적인 방법으로는 어렵다는 생각을 하게 되었습니다. 1. 입력을 받고 올바른 문자열들을 한 번 stack을 이용해 걸러줍니다. 2. 걸러진 문자열들 또한 길이가 짝수입니다. '{ }' 를 하나의 세트로 지웠기 때문입니다. 따라서 '{'와 '}'의 개수는 둘 다 짝수이거나 둘 다 홀수인 두 가지 경우뿐입니다. 즉, 홀수 ..
(Python) - 백준(BOJ) 1340번 : 연도 진행바 https://www.acmicpc.net/problem/1340 1340번: 연도 진행바 평년일 때, 각 달은 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31일이 있다. 윤년에는 2월이 29일이다. 윤년은 그 해가 400으로 나누어 떨어지는 해 이거나, 4로 나누어 떨어지면서, 100으로 나누어 떨어지지 www.acmicpc.net 문자열 처리 문제였습니다. 풀이방법 1. 현재 연도가 윤년이냐 아니냐에 따라 2월의 날짜 수가 달라집니다. 이 말은 윤년에는 하루가 366일이라는 의미입니다. 따라서 먼저 윤년인지 여부를 판단합니다. 2. 비교하는 최소의 단위가 '분'이기 때문에 입력 받은 정보를 분 단위로 치환해야 합니다. * 날의 수를 셀 때 입력받은 달의 이전 달까지..
(C++) - 백준(BOJ) 21734번 : SMUPC의 등장 https://www.acmicpc.net/problem/21734 21734번: SMUPC의 등장 2021년 5월 8일 SMUPC 대회의 첫 개최에 신이 난 화은이는 SMUPC를 기념하기 위해 "SMUPC"를 예술적으로 출력하는 프로그램을 작성하고자 했다. 화은이는 각 알파벳에 해당하는 아스키코드 값을 10진 www.acmicpc.net 아스키 코드를 이용해보는 문자열 문제였습니다. Code #include using namespace std; string s; int getSum(int ascii){ int tmp = ascii; int sum = 0; while(tmp){ sum += tmp%10; tmp /= 10; } return sum; } int main(){ cin >> s; for(int..
(C++) - 프로그래머스(2021 카카오 채용연계형 인턴십) : 숫자 문자열과 영단어 https://programmers.co.kr/learn/courses/30/lessons/81301?language=cpp 코딩테스트 연습 - 숫자 문자열과 영단어 네오와 프로도가 숫자놀이를 하고 있습니다. 네오가 프로도에게 숫자를 건넬 때 일부 자릿수를 영단어로 바꾼 카드를 건네주면 프로도는 원래 숫자를 찾는 게임입니다. 다음은 숫자의 일부 자 programmers.co.kr 간단한 문자열 문제였습니다. 풀이방법 1. map에 각 대응 문자와 숫자를 저장합니다. 2. 단어를 읽으며 적절히 매칭되었다면 정답에 문자를 추가해줍니다. 3. 문자를 수로 바꿔 반환합니다. Code #include using namespace std; int solution(string s) { map m; m["zero"] ..