문제 링크입니다: https://www.acmicpc.net/problem/15355
15355번: Programiranje
Little Leticija is preparing for a programming exam. Even though she has solved a lot of tasks, there’s one still left unsolved, so she is asking you for help. You are given the word S and Q queries. In each query, you are given positive integers A, B, C a
www.acmicpc.net
간단한 문자열 처리 알고리즘 문제였습니다.
C~D 인덱스 사이에 있는 문자들이 A~B 인덱스 사이에 있는 문자들로 구성할 수 있는지를 판별하면 되는 문제였습니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
string S; | |
cin >> S; | |
int Q; | |
cin >> Q; | |
for (int q = 0; q < Q; q++) | |
{ | |
int A, B, C, D; | |
cin >> A >> B >> C >> D; | |
int alphabet[26] = { 0, }; | |
for (int i = A - 1; i < B; i++) | |
{ | |
alphabet[S[i] - 'a']++; | |
} | |
bool flag = true; | |
for (int i = C - 1; i < D; i++) | |
{ | |
if (--alphabet[S[i] - 'a'] < 0) | |
{ | |
flag = false; | |
cout << "NE\n"; | |
break; | |
} | |
} | |
if (flag) | |
{ | |
cout << "DA\n"; | |
} | |
} | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 2980번 도로와 신호등 (2) | 2020.04.04 |
---|---|
백준 4796번 캠핑 (0) | 2020.03.28 |
백준 3053번 택시 기하학 (0) | 2020.03.21 |
백준 17362번 수학은 체육과목 입니다 2 (0) | 2020.03.21 |
백준 4889번 안정적인 문자열 (0) | 2020.03.21 |