Submission
Status:
PPPPPPPP-P
Subtask/Task Score:
90/100
Score: 90
User: Alif_Sama
Problemset: อะนาแกรม 2
Language: cpp
Time: 0.003 second
Submitted On: 2025-10-07 20:29:29
#include <iostream>
using namespace std;
int main() {
string a,b;
cin >> a >> b;
int cnt1[255] = {0};
int cnt2[255] = {0};
//frequency
for (int i = 0; a[i] != '\0'; i++) {
cnt1[a[i]]++;
}
for (int i = 0; b[i] != '\0'; i++) {
cnt2[b[i]]++;
}
//print A-H of string 1-2
for (int i = 'A'; i <= 'H'; i++) {
cout << cnt1[i] << " ";
}
cout << "\n";
for (int i = 'A'; i <= 'H'; i++) {
cout << cnt2[i] << " ";
}
cout << "\n";
// subtracting
int arr[8];
for (int i = 'A'; i <= 'H'; i++) {
arr[i-'A'] = abs(cnt1[i] - cnt2[i]);
}
for (int i = 0; i < 8; i++) {
cout << arr[i] << " ";
}
cout << "\n";
//checking if it is anagram
int anagram = 0;
for (int i = 0; i < 8; i++) {
if (arr[i] == 1) {
anagram++;
}
}
//printing condition
if (anagram > 3) {
cout << "no";
} else {
cout << "anagram";
}
}