Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: bossc
Problemset: อะนาแกรม 2
Language: cpp
Time: 0.002 second
Submitted On: 2026-05-10 14:25:13
#include <iostream>
#include <string>
#include <cmath> // Included to use abs()
using namespace std;
int main() {
string d1, d2;
int ctr = 0;
// Read the two strings
cin >> d1 >> d2;
// Arrays to store counts for A-H
int arr1[8] = {0}, arr2[8] = {0};
// Count characters for the first string
for (char i : d1) {
arr1[i - 'A']++; // Using 'A' is functionally identical to 65 but easier to read
}
// Count characters for the second string
for (char i : d2) {
arr2[i - 'A']++;
}
// Print the counts for the first string
for (int i = 0; i < 8; i++) {
cout << arr1[i] << " ";
}
cout << endl;
// Print the counts for the second string
for (int i = 0; i < 8; i++) {
cout << arr2[i] << " ";
}
cout << endl;
// Calculate, print, and sum the absolute differences
for (int i = 0; i < 8; i++) {
int diff = abs(arr1[i] - arr2[i]);
cout << diff << " ";
ctr += diff; // Add the actual difference, not just 1
}
cout << endl;
// Check if the total difference is 3 or less
if (ctr <= 3) {
cout << "anagram\n";
} else {
cout << "no\n";
}
return 0;
}