[Boj]11326:Strfry

2024. 8. 4. 17:11Algorithm

1. problem : 

https://www.acmicpc.net/problem/11328

 

 

2. solution 1 :

#include <bits/stdc++.h>

using namespace std;

int main(void) {
	ios::sync_with_stdio(0);
	cin.tie(0);

	int N;
	cin >> N;
	while (N--) {
		int a[26] = {};
		string s1, s2;
		cin >> s1 >> s2;
		
		for (auto c : s1) a[c - 'a']++;
		for (auto c : s2) a[c - 'a']--;

		bool isPossible = true;

		for (int i : a) {
			if (i != 0) {
				isPossible = false;
			}
		}
		if (isPossible) cout << "Possible\n";
		else cout << "Impossible\n";
	}
}

코드출처 : https://github.com/encrypted-def/basic-algo-lecture/blob/master/0x03/solutions/11328.cpp

 

basic-algo-lecture/0x03/solutions/11328.cpp at master · encrypted-def/basic-algo-lecture

바킹독의 실전 알고리즘 강의 자료. Contribute to encrypted-def/basic-algo-lecture development by creating an account on GitHub.

github.com

 

 

3. solution 2 : 

from collections import Counter
N = int(input())
words = [tuple(input().split()) for _ in range(N)]
for word in words:
    word1_dict = Counter(word[0])
    word2_dict = Counter(word[1])
    if word1_dict == word2_dict:
        print("Possible") 
    else:
        print("Impossible")

 

'Algorithm' 카테고리의 다른 글

[BOJ] 1406: 에디터  (0) 2024.08.05
[Boj]1919: 애너그램 만들기  (0) 2024.08.04
[Boj] 10807번 : 개수 세기  (0) 2024.08.04
[Boj]3273번 : 두 수의 합  (0) 2024.08.04
[Boj]1475 :방 번호  (0) 2024.08.04