算典05_例题_04_UVA-156
2017-04-02 14:57
295 查看
Ananagrams
题意
输入一些单词区(分大小写),如果某个单词与其他任何单词没有联系,则输入这个单词。两个单词有联系的意思是忽略他们的大小写之后和字母的顺序,所有的字母出现的次数都相等, 如dog 和God
要求结果按字典序输出
题解
STL入门水题。使用两个string数组记录输入的单词和处理后的单词,处理后的意思即为都转为小写,然后用sort排序后的单词
并使用一个map
#include <iostream> #include <cstdio> #include <queue> #include <cstring> #include <algorithm> #include <cmath> #include <vector> #include <string> #include <sstream> #include <set> #include <map> using namespace std; const int maxn = 1e3 + 5; const int INF = (1<<31)-1; #define met(a, b) memset(a, b, sizeof(a)); #define IN freopen("in.txt", "r", stdin); typedef long long LL; string a, s[maxn], ss[maxn]; int sid; map<string, int> m; set<string> ans; int main(){ #ifdef _LOCAL IN; #endif // _LOCAL sid = 0; while(cin >> a && a[0] != '#') { s[sid] = a; int len = a.size(); for(int i = 0; i < len; ++i) a[i] = tolower(a[i]); sort(a.begin(), a.end()); ss[sid++] = a; if(!m.count(a)) m[a] = 0; ++m[a]; } for(int i = 0; i < sid; ++i) { if(m[ss[i]] <= 1) ans.insert(s[i]); } for(set<string>::iterator it = ans.begin(); it!= ans.end(); ++it) cout << (*it) <<endl; return 0; }
相关文章推荐
- 算典04_例题_05_UVA-512
- 算典04_习题_05_UVA-1590
- 算典04_例题_01_UVA-1339
- 算典05_例题_02_UVA-101
- 算典04_例题_06_UVA-12412
- 算典05_例题_03_UVA-10815
- 算典05_例题_08_UVA-400
- 算典05_例题_10_UVA-207
- 算典04_例题_02_UVA-489
- 算典05_例题_11_UVA-814
- 例题5-4 UVa156 Ananagrams(STL:map)
- 《算法竞赛入门经典2ndEdition 》例题5-4 反片语(Ananagrams, Uva156)
- 算典04_例题_04_UVA-213
- 算典05_例题_05_UVA-12096
- 算典05_例题_09_UVA-1592
- 算法竞赛入门经典第五章例题5-4 Ananagrams UVA - 156
- 例题5-4 反片语 UVa156
- 算典05_例题_12_UVA-221
- 算典03_例题_04_Uva-340
- 【例题5-4 UVA - 156】Ananagrams