uva156---map的使用
code:
/*
map 用法: 格式 map<T,T>name;
用于两种格式的映射 且其可以使用[]来映射出另外的value
常用于 计数,或者 绑定两者之间的关系
常用操作:
begin() 返回指向map头部的迭代器
clear() 删除所有元素
count() 返回指定元素出现的次数
empty() 如果map为空则返回true
end() 返回指向map末尾的迭代器
equal_range() 返回特殊条目的迭代器对
erase() 删除一个元素
find() 查找一个元素
get_allocator() 返回map的配置器
insert() 插入元素
key_comp() 返回比较元素key的函数
lower_bound() 返回键值>=给定元素的第一个位置
max_size() 返回可以容纳的最大元素个数
rbegin() 返回一个指向map尾部的逆向迭代器
rend() 返回一个指向map头部的逆向迭代器
size() 返回map中元素的个数
swap() 交换两个map
upper_bound() 返回键值>给定元素的第一个位置
value_comp() 返回比较元素value的函数
*/
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cctype>
#include <algorithm>
using namespace std;
map<string,int> cnt;
vector<string> word;
string repr(const string& s){ //将 字符串标准化 --将输入的字符转化为小写,然后按字典序 排序
string a = s;
for(int i = 0;i < a.length();i++)
a[i] = tolower(a[i]);
sort(a.begin(),a.end());
return a;
}
int main(){
string s;
while(cin >> s){
if(s == "#") break;
word.push_back(s);
string r = repr(s);
if(!cnt.count(r)) cnt[r] = 0; //init
cnt[r]++;
}
vector<string> ans;
for(int i= 0;i <word.size();i++)
if(cnt[repr(word[i])] == 1) ans.push_back(word[i]);
sort(ans.begin(),ans.end());
for(int i=0; i < ans.size();i++)
cout << ans[i] <<"\n";
return 0;
}
浙公网安备 33010602011771号