백준 11328

최성욱·2025년 2월 25일
0
#include <iostream>
#include<vector>
using namespace std;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, i, j;
	cin >> n;
	for (i = 0;i < n;i++) {
		
		string a, b;
		cin >> a >> b;
		vector<int> cnt(26);
		for (j = 0;j < a.length();j++) {
			cnt[a[j] - 'a']++;
			
		}
		for (j = 0;j < b.length();j++) {
			cnt[b[j] - 'a']--;
		}
		bool flag = true;
		for (j = 0;j < 26;j++) {
			if (cnt[j] != 0) {
				flag = false;
			}
		}
		if (flag) {
			cout << "Possible" << "\n";
		}
		else {
			cout << "Impossible" << "\n";
		}
	}
	return 0;
	
	
}

주요 로직 : 문자열 a, b를 입력받고 a의 배열 count를 담기
-> b를 순회하면서 해당 문자열일 경우 count수를 -1하기
만약 count배열이 모두 0이 아닌 경우 "Impossible" 출력!

profile
성장을 지향하는 개발자

0개의 댓글