Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: KanemiyaKana

Problemset: อะนาแกรม 2

Language: cpp

Time: 0.003 second

Submitted On: 2026-09-27 14:05:18

#include <iostream>
#include <string>
#include <cctype>  // needed for isupper
#include <cmath>   // needed for absolute
#include <sstream> // needed for instant divide every whitespace
using namespace std;

string counter(string subject)
{
    string returnstring = "";
    string alphatemplate = "ABCDEFGH";
    for (int i = 0; i < alphatemplate.length(); i++)
    {
        int temp = 0;
        for (int j = 0; j < subject.length(); j++)
        {
            if (alphatemplate[i] == subject[j])
            {
                temp = temp + 1;
            }
        }
        string strtemp = to_string(temp);
        returnstring += strtemp;
        returnstring += " ";
    }
    return returnstring;
}

string compare(string ana1, string ana2)
{
    stringstream ss1(ana1);
    stringstream ss2(ana2);
    string returnstring = "";
    for (int i = 0; i < 8; i++)
    {
        int temp1 = 0;
        int temp2 = 0;
        ss1 >> temp1;
        ss2 >> temp2;
        int difference = abs(temp1 - temp2);
        string strdifference = to_string(difference);
        returnstring += strdifference;
        returnstring += " ";
    }
    return returnstring;
}

string anagramchecker(string ana)
{
    string returnstring = "";
    int counter = 0;
    for (int i = 0; i < ana.length() - 1; i = i + 2)
    {
        if (ana[i] != '0')
        {
            counter++;
        }
    }
    if (counter > 3)
    {
        returnstring += "no";
    }
    else
    {
        returnstring += "anagram";
    }
    return returnstring;
}

int main()
{
    string input1;
    string input2;
    cin >> input1;
    cin >> input2;
    for (int i = 0; i < input1.length(); i++)
    {
        if (input1[i] != 'A' && input1[i] != 'B' && input1[i] != 'C' && input1[i] != 'D' && input1[i] != 'E' && input1[i] != 'F' && input1[i] != 'G' && input1[i] != 'H')
        {
            return 0;
        }
        else if (islower(input1[i]))
        {
            return 0;
        }
        else if (input1.length() > 10000)
        {
            return 0;
        }
    }
    for (int i = 0; i < input2.length(); i++)
    {
        if (input2[i] != 'A' && input2[i] != 'B' && input2[i] != 'C' && input2[i] != 'D' && input2[i] != 'E' && input2[i] != 'F' && input2[i] != 'G' && input2[i] != 'H')
        {
            return 0;
        }
        else if (islower(input2[i]))
        {
            return 0;
        }
        else if (input2.length() > 10000)
        {
            return 0;
        }
    }
    string output1 = counter(input1);
    string output2 = counter(input2);
    cout << output1 << "\n";
    cout << output2 << "\n";

    string difference = compare(output1, output2);
    cout << difference << "\n";

    string yn = anagramchecker(difference);
    cout << yn;
}