본문 바로가기

Beakjoon/string

(6)
[백준] 9417번 최대 GCD (C++) - substr(), find()를 활용해서 특정 문자 기준으로 자르기, Euclidean algorithm 문제 https://www.acmicpc.net/problem/9417 9417번: 최대 GCD 첫째 줄에 테스트 케이스의 개수 N (1 > n; cin.ignore(); while(n--){ int result..
[백준] 1551번 수열의 변화 (C++) - stringstream, split 문제 https://www.acmicpc.net/problem/1551 1551번: 수열의 변화 첫째 줄에 수열의 크기 N과 K가 주어진다. N은 20보다 작거나 같은 자연수이고, K는 0보다 크거나 같고, N-1보다 작거나 같은 정수이다. 둘째 줄에는 수열이 ‘,’로 구분되어 주어진다. 수열을 이루 www.acmicpc.net 코드 #include #include #include #include using namespace std; vector split(string input, char delimiter) { vector answer; stringstream ss(input); string temp; while (getline(ss, temp, delimiter)) { answer.push_back(..
[백준] 2998번 8진수 (C++) - str.insert(), str.substr() 문제 https://www.acmicpc.net/problem/2998 2998번: 8진수 창영이는 여러 가지 진법을 공부하고 있다. 창영이는 어제 2진법을 배웠고, 오늘은 8진법을 배웠다. 이제, 2진법 수를 8진법 수로 변환하려고 한다. 창영이가 사용한 방법은 다음과 같다. 2진수의 www.acmicpc.net 코드 #include #include using namespace std; string arr[8] = {"000","001","010","011","100","101","110","111"}; int main(){ string binary; cin >> binary; int length= binary.length(); if(length%3!=0){ for(int i=0; i
[백준] 2857번 FBI (C++) - str.find() 문제 https://www.acmicpc.net/problem/2857 2857번: FBI 5개 줄에 요원의 첩보원명이 주어진다. 첩보원명은 알파벳 대문자, 숫자 0~9, 대시 (-)로만 이루어져 있으며, 최대 10글자이다. www.acmicpc.net 코드 #include #include using namespace std; int main(){ bool flag = true; for(int i=1; i> s; if(s.find("FBI") != -1){ cout
[백준] 11656번 접미사 배열 (C++) - str.substr() 문제 https://www.acmicpc.net/problem/11656 11656번: 접미사 배열 첫째 줄에 문자열 S가 주어진다. S는 알파벳 소문자로만 이루어져 있고, 길이는 1,000보다 작거나 같다. www.acmicpc.net 코드 #include #include #include #include using namespace std; int main(){ string s; cin >> s; vector v; for(int i=0; i
[백준] 10809번 알파벳 찾기 (C++) 문제 https://www.acmicpc.net/problem/10809 10809번: 알파벳 찾기 각각의 알파벳에 대해서, a가 처음 등장하는 위치, b가 처음 등장하는 위치, ... z가 처음 등장하는 위치를 공백으로 구분해서 출력한다. 만약, 어떤 알파벳이 단어에 포함되어 있지 않다면 -1을 출 www.acmicpc.net 코드 way1(내 풀이) #include #include using namespace std; int main(){ string s; cin >> s; int alphabet[26]; for(int i=0; i