Ananagrams UVA 156(反片语)
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- using namespace std;
map
mp; - vector
vec; - string lower1(const string &s){ 将大写转换成小写,其中 tolower位于头文件cctype中
- string s1=s;
- for(int i=0;i<s1.length();i++){
- s1[i]=tolower(s1[i]);
- }
- sort(s1.begin(),s1.end()); //对于string 类字符串的从小到大的排序
- return s1;
- }
- int main(){
- string str;
- while(cin>>str){
- if(str==”#“)break;
- vec.push_back(str);
- string temp=lower1(str);
- if(!mp.count(temp))mp[temp]=0; //判断当转换成小写之后是否在map中出现
- mp[temp]++;
- }
vector
temp_v; - for(int i=0;i<vec.size();i++){
- if(mp[lower1(vec[i])]==1)temp_v.push_back(vec[i]);
- }
- sort(temp_v.begin(),temp_v.end());
- for(vector
::iterator iter=temp_v.begin();iter!=temp_v.end();iter++){ - cout<<*iter<<endl;
- }
- return 0;
- }
//for(int i=0;i<temp_v.size();i++){
// cout<<temp_v[i]<<endl;
//} //当然遍历vector容器可以通过下标形式访问,更加直接
还没有评论,来说两句吧...