欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

映射:map

发布时间:2025/3/15 34 豆豆
生活随笔 收集整理的这篇文章主要介绍了 映射:map 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

2018-5-11

输入一些单词,找出满足以下条件的单词:
该单词不能通过字母重排,得到输入文本中的另外一个单词。
在判断是否满足条件时,字母不区分大小写,但在输出时应该保留输入中的大小写,按照字典序进行排列(大写字母在小写字母的前面)。

#include<iostream> #include<map> #include<set> #include<vector> #include<string> #include<algorithm> using namespace std;map<string,int>cnt; set<string>fir;string init(string x){for (int i=0;i<x.length();i++){x[i]=tolower(x[i]);}sort(x.begin(),x.end());return x; }int main(){string s,buf;while (cin>>s){if (s[0]=='#') break;fir.insert(s);string tmp=init(s);if (!cnt[tmp]){cnt[tmp]=1;}else{cnt[tmp]++;}}for (set<string>::iterator it=fir.begin();it!=fir.end();it++){if (cnt[init(*it)]==1) cout<<*it<<endl;}return 0; }

总结

以上是生活随笔为你收集整理的映射:map的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。