UVA156 反片语 Ananagrams

简介: UVA156 反片语 Ananagrams

题意翻译

题目大意 输入一些单词,找出所有满足如下条件的单词:该单词不能通过字母重排,得到输入文本的另外一个单词。在判断是否满足条件时,字母不分大小写,但在输出时应保留输入的大小写,按字典序排列。

输入样例

ladder came tape soon leader acme RIDE lone Dreis peat
ScAlE orb eye Rides dealer NotE derail LaCeS drIed
noel dire Disk mace Rob dries
#

输出样例

Disk
NotE
derail
drIed
eye
ladder
soon


代码

#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<algorithm>
using namespace std;
/*
题目思路
1.使用vector v1存储单词,以便后期使用
2.写一个函数:可以将单词变成小写,有序
3.使用map集合统计每个单词(函数处理后)的个数.
4.遍历vector v1如果  在map中出现的次数为1那么就找到啦满足题意的单词,再加到新的vector  v2中;
5.对v2进行排序,然后输出即可.
*/
string s;
vector<string> v1, v2;
map<string, int> m;
string low_sort(string s1) {
  for (int i = 0; i < s1.size(); i++) {
    s1[i] = tolower(s1[i]);
  }
  sort(s1.begin(), s1.end());
  return s1;
}
int main() {
  while (cin >> s && s[0] != '#') {
    v1.push_back(s);
    if (!m.count(low_sort(s))) {
      m[low_sort(s)] = 1;
    }
    else {
      m[low_sort(s)]++;
    }
  }
  for (int i = 0; i < v1.size(); i++) {
    if (m[low_sort(v1[i])] == 1) {
      v2.push_back(v1[i]);
    }
  }
  sort(v2.begin(), v2.end());
  for (int i = 0; i < v2.size(); i++) {
    cout << v2[i] << endl;
  }
  return 0;
}
相关文章
uva10038 Jolly Jumpers
uva10038 Jolly Jumpers
37 0
Uva10001 Garden of Eden
Uva10001 Garden of Eden
46 0
uva 10340 all in all
输入两个字符串s和t,判断是否可以从t中删除0个或多个字符(其他字符顺序不变),得到字符串是。
37 0
UVa11968 - In The Airport
UVa11968 - In The Airport
55 0
UVa10123 No Tipping
UVa10123 No Tipping
61 0
UVa11776 - Oh Your Royal Greediness!
UVa11776 - Oh Your Royal Greediness!
51 0
uva375 Inscribed Circles and Isosceles Triangles
uva375 Inscribed Circles and Isosceles Triangles
39 0
uva10152 ShellSort
uva10152 ShellSort
61 0
uva10112 Myacm Triangles
uva10112 Myacm Triangles
42 0
uva127 "Accordian" Patience
uva127 "Accordian" Patience
43 0