Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: KurtCobain

Problemset: อะนาแกรม 2

Language: cpp

Time: 0.006 second

Submitted On: 2025-10-03 14:59:55

#include <iostream>
#include <string>
#include <map>
#include <cmath>
using namespace std;

int main(){
   // Anagram 2
   string s1,s2;
   cin >> s1 >> s2;
   map<char , int> matched1 = {
   {'A',0},
   {'B',0},
   {'C',0},
   {'D',0},
   {'E',0},
   {'F',0},
   {'G',0},
   {'H',0}
};
   map<char,int> matched2 = matched1;
   map<char, int> diff = matched1;
   for (char c1 : s1){
    matched1[c1]++;
   }
   for (char c2 : s2){
    matched2[c2]++;
   }
   for (auto p=matched1.begin();p!=matched1.end();p++){
      cout << p->second << " ";
   }
   cout << '\n';
   for (auto p=matched2.begin();p!=matched2.end();p++){
      cout << p->second << " ";
   }
   string b = "ABCDEFGH";
   int d = 0;
   for (char c : b){
      int k = abs(matched1[c] - matched2[c]);
      if (k != 0) d++;
      diff[c] = k;
   }
   cout << '\n';
   for (auto p=diff.begin();p!=diff.end();p++){
      cout << p->second << " ";
   }
   cout << '\n';
   if (d > 3){
    cout << "no" << '\n';
   }
   else{
    cout << "anagram" << '\n';
   }
}