NO IMAGE
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
void countfreq(string s,vector<int>& freq){
int len=s.size(),count=1;
for(int i=1;i<len;  i){
if(s[i]==s[i-1]){
count;
}
else{
freq.push_back(count);
count=1;
}
}
freq.push_back(count);
}
bool cmp(int a,int b)
{
return a>b;
}
int main(){
string a,b,c;
cin>>a>>b;
int len=a.size();
if(len==1){
cout<<"YES";
return 0;
}
sort(&a[0],&a[len]);//
sort(&b[0],&b[len]);//
//cout<<a<<endl<<b<<endl;
vector<int> afreq;
vector<int> bfreq;
countfreq(a,afreq);
countfreq(b,bfreq);
if(afreq.size()!=bfreq.size()){
cout<<"NO";
return 0;
}
//cout<<afreq.size()<<endl;
len=afreq.size();
sort(&afreq[0],&afreq[len],cmp);//
sort(&bfreq[0],&bfreq[len],cmp);//
for(int i=0;i<len;  i){
//cout<<afreq[i]<<" "<<bfreq[i]<<endl;
if(afreq[i]!=bfreq[i]){
cout<<"NO";
return 0;
}
}
/*vector<vector<int> > fluency;
fluency.push_back({26});//
int table[26]={0};
for(int i=0;i<len;  i){
table[a[i]-'A'];
}
int max=0;
for(int i=0;i<26;  i){
fluency[]
if(table[i]>max)
max=table[i];
}
if(max==1)*/
cout<<"YES";
return 0;
}

上面只統計頻次,好像不夠嚴謹。最後一部分改成下面,不過,WA

	
for(int i=0,j=0;i<len;  i,  j){
j%=len;
if(afreq[i]!=bfreq[j]){
int k=j 1;
k%=len;
while((afreq[i]!=bfreq[k])&&(k!=j)){
k;
k%=len;
}
if(k==j){
cout<<"NO";
return 0;
}
else{
j=k;
}
}
}