알고리즘

[알고리즘] 백준 6996 - 애너그램 (C++)

blueberrysoda 2024. 10. 23. 23:57

[문제 링크] : https://www.acmicpc.net/problem/6996

#include <iostream>
#include <algorithm>
using namespace std;

int main(){
    int T;
    string a, b, tmp1, tmp2;
    cin >> T;

    for(int i=0; i<T; i++){
        cin >> a >> b;
        tmp1 = a, tmp2 = b;
        
        sort(a.begin(), a.end());
        sort(b.begin(), b.end());
        
        if(a == b){
            cout << tmp1 << " & " << tmp2 << " are anagrams.\n";
        }
        else{
            cout << tmp1 << " & " << tmp2 << " are NOT anagrams.\n";
        }
    }
    return 0;
}