确定字符串是否包含唯一字符
#include<bits/stdc++.h>
using namespace std;
int main(){ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);map<char,int>m;string s;cin>>s;for(int i=0;i<s.size();++i){if(isalpha(s[i]))s[i]=tolower(s[i]);if(m.find(s[i]) != m.end()){cout<<"NO";return 0;}else{m[s[i]]=true;}}cout<<"YES";return 0;
}
确定字符串是否是另一个的排列
#include<bits/stdc++.h>
using namespace std;
int main(){ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);map<char,int>m1,m2;string s1,s2;cin>>s1>>s2;if(s1.size()!=s2.size()){cout<<"NO";return 0;}for(int i=0;i<s1.size();++i)++m1[s1[i]];for(int i=0;i<s2.size();++i)++m2[s2[i]];for(int i=0;i<s1.size();++i){if(m1[s1[i]]!=m2[s2[i]]){cout<<"NO";return 0;}}cout<<"YES";return 0;
}