Untitled

mail@pastecode.io avatar
unknown
c_cpp
a year ago
621 B
8
Indexable
Never
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

bool areAnagrams(const string& word1, const string& word2) {
    if (word1.length() != word2.length()) {
        return false;
    }

    string sortedWord1 = word1;
    string sortedWord2 = word2;

    sort(sortedWord1.begin(), sortedWord1.end());
    sort(sortedWord2.begin(), sortedWord2.end());

    return sortedWord1 == sortedWord2;
}

int main() {
    string word1, word2;
    cin >> word1 >> word2;

    if (areAnagrams(word1, word2)) {
        cout << "1" << endl;
    } else {
        cout << "0" << endl;
    }

    return 0;
}