不重複單字,重新排列成另外一個單字也不行
例如: 有 eat 則 ate不行
關鍵: 單字的標準化-> 全部小寫 , a排到z
map 映射
- 類似python的dict
- Key為標準化單字 value 為出現次數
注意By reference 改變Vector記憶體指向的值
- Vector 儲存未標準化
- “判斷”使用標準化
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using namespace std ;
map<string,int> cnt ;
vector <string> word ;
string repr(string &s){
string ans = s ;
for(int i = 0 ; i < s.length() ; i++ ){
ans[i] = tolower(s[i]) ;
}
sort(ans.begin() , ans.end()) ;
//不要直接改變原字串,因為by reference 會直接改變指標所指向的值
return ans ;
}
int main(){
string s ,r ;
while(cin >> s){
// cout << s<<endl;
if(s[0] == '#') break;
word.push_back(s) ;
r = repr(s) ;
/// cout << s<<endl;
if(!cnt.count(r)) cnt[r] = 0 ;
cnt[r]++ ;
}
vector<string >ans ;
for(int i = 0 ; i< word.size() ; i++){
if(cnt[repr(word[i]) ] ==1) ans.push_back(word[i]) ;
//cout << "answer : "<<word[i] << endl ;
}
for(int i = 0 ; i<ans.size() ; i++){
cout << "answer : "<<ans[i] << endl ;
}
return 0 ;
}