문제 링크입니다: https://www.acmicpc.net/problem/11328
11328번: Strfry
문제 C 언어 프로그래밍에서 문자열(string)은 native한 자료형이 아니다. 사실, 문자열은 그저, 문자열의 끝을 표시하기 위한 말단의 NULL이 사용된, 문자들로 이루어진 문자열일 뿐이다. 하지만 프로그래밍 언어에서 문자열을 다루는 것은 매우 중요하기 때문에, C 표준 라이브러리는 문자열을 다루는 데에 매우 유용한 함수들을 제공하고 있다 : 그들 중에는 strcpy, strcmp, strtol, strtok, strlen, strcat 가 있다.
www.acmicpc.net
BaaaaaaaaaaarkingDog님의 문제집에 수록된 문제집을 풀고 있습니다.
아직 초기 문제집이기 때문에 간단한 문제였습니다.
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; | |
const int MAX = 26; | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
int N; | |
cin >> N; | |
for (int n = 0; n < N; n++) | |
{ | |
string a, b; | |
cin >> a >> b; | |
if (a.length() != b.length()) | |
{ | |
cout << "Impossible\n"; | |
continue; | |
} | |
int alphabets[MAX] = { 0, }; | |
for (int i = 0; i < a.length(); i++) | |
{ | |
alphabets[a[i] - 'a']++; | |
} | |
bool possible = true; | |
for (int i = 0; i < b.length(); i++) | |
{ | |
if (--alphabets[b[i] - 'a'] < 0) | |
{ | |
possible = false; | |
cout << "Impossible\n"; | |
break; | |
} | |
} | |
if (possible) | |
{ | |
cout << "Possible\n"; | |
} | |
} | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 10868번 최솟값 (0) | 2020.03.08 |
---|---|
백준 1043번 거짓말 (0) | 2020.03.05 |
백준 1267번 핸드폰 요금 (0) | 2020.03.01 |
백준 10804번 카드 역배치 (0) | 2020.03.01 |
백준 2108번 통계학 (0) | 2020.02.24 |