11328번: Strfry 이 문제입니ㅏㄷ
#include <bits/stdc++.h>
using namespace std;
bool isPrime(int n) {
if (n <= 1) return false;
if (n == 2) return true;
if (n % 2 == 0) return false;
for (int i = 3; i <= sqrt(n); i += 2) {
if (n % i == 0) return false;
}
return true;
}
// 알파벳에 소수 할당하는 함수
unordered_map<char, int> assignPrimesToAlphabet() {
unordered_map<char, int> alphaPrimeMap;
int currentNumber = 2;
for (char c = 'a'; c <= 'z'; ++c) {
while (!isPrime(currentNumber)) {
currentNumber++;
}
alphaPrimeMap[c] = currentNumber;
currentNumber++;
}
return alphaPrimeMap;
}
int n;
string case1,case2;
int main(){
unordered_map<char, int> alphaPrimes = assignPrimesToAlphabet();
cin >> n;
int ans[n];
for(int i = 0; i < n; i++){
cin >> case1 >> case2;
int temp1[case1.length()];
int temp2[case2.length()];
int multi1 = 1, multi2 = 1;
for(int j = 0; j < case1.length(); j++){
temp1[j] = alphaPrimes[case1[j]];
temp2[j] = alphaPrimes[case2[j]];
multi1 *= temp1[j];
multi2 *= temp2[j];
}
cout << multi1 << '1 ' << multi2 << 'n';
if(multi1 == multi2) ans[i] = 1;
else ans[i] = 0;
}
for(int i = 0; i < n; i++){
if(ans[i]) cout << "Possible\n";
else cout << "Impossible\n";
}
}
multi1하고 2는 궁금해서 출력해본거라 문제 제출할때는 지웠슴당
ps갤러리로