Given two strings s and t, write a function to determine if t is an anagram of s.
For example,
s = "anagram", t = "nagaram", return true.
s = "rat", t = "car", return false.
Note:
You may assume the string contains only lowercase alphabets.
Follow up:
What if the inputs contain unicode characters? How would you adapt your solution to such case?
思路:对两个string排序,然后判断它们是否相等。
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
using namespace std;
/*********************************提交部分*********************************/
class Solution
{
public:
bool isAnagram(string s, string t)
{
sort(s.begin(),s.end());
sort(t.begin(),t.end());
if(s==t)
return true;
return false;
}
};
/**************************************************************************/
int main()
{
string a,b;
cin>>a>>b;
Solution S;
if(S.isAnagram(a,b))
printf("Yes\n");
else
printf("No\n");
return 0;
}