生活随笔
收集整理的這篇文章主要介紹了
映射: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的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。