题解:CF2167B Your Name

· · 题解

codeforces题目传送门

思路

将输入的两个字符串分别按照字典序排序,最后检查排序后的两个字符串是否相等。

关键代码:

sort(s1.begin(),s1.end());
sort(s2.begin(),s2.end());
if(s1==s2) cout <<"YES"<<'\n';
else cout <<"NO"<<'\n';

AC Code:

#include <bits/stdc++.h>
using namespace std;
void solve()
{
    int n;
    string s1,s2;
    cin >>n>>s1>>s2;
    sort(s1.begin(),s1.end());
    sort(s2.begin(),s2.end());
    if(s1==s2) cout <<"YES"<<'\n';
    else cout <<"NO"<<'\n';
}
int main()
{
    int t;
    cin >>t;
    while(t--)
    {
        solve();
    }
    return 0;
}