https://www.acmicpc.net/problem/11328
조금 마음에 들진 않지만,간편하게 인덱스를 문자로 받고 싶어서 map을 썼다.
배열로 쓰려면 아스키코드 문자를 이용해서 인덱스를 지정하면 될 듯하다.
#include<iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <climits>
#include <queue>
#include <set>
#include <cmath>
#include <stack>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
string temp;
string temp2;
while (n--) {
bool flag = true;
map<char, int> first_string;
map<char, int> second_string;
cin >> temp;
for (char i: temp) {
first_string[i]++;
}
cin >> temp2;
for (char i: temp2) {
second_string[i]++;
}
if (temp.size() == temp2.size()) {
for (char i: temp) {
if (first_string[i] != second_string[i]) {
flag = false;
cout << "Impossible\n";
break;
}
}
if (flag) {
cout << "Possible\n";
}
} else {
cout << "Impossible" << "\n";
}
}
return 0;
}
'PS > BOJ' 카테고리의 다른 글
[백준] 1406. 에디터(c++) (0) | 2025.01.26 |
---|---|
[백준] 1919. 애너그램 만들기(c++) (0) | 2025.01.21 |
[백준] 13300. 방 배정(c++) (0) | 2025.01.19 |
[백준] 10807. 개수 세기(c++) (0) | 2025.01.19 |
[백준] 3273. 두 수의 합(c++) (0) | 2025.01.16 |