An anagram is a word or phrase formed by rearranging the letters of another word or phrase. For example, “carthorse” is an anagram of “orchestra”. Blanks within a phrase are ignored in forming anagrams. Thus, “orchestra” and “horse cart” are also anagrams.
    Write a program that reads a list of phrases and prints all pairs of anagrams occurring in the list.
Input
The input file will contain a single integer at the first line of the input, indicate the number of test case you need to test followed by a blank line.
    Each test case will consist of from 1 to 100 lines. A completely empty or blank line signals the end of input. Each line constitutes one phrase.
Output
For each test case, output some number of lines (including possibly 0 if there are no anagrams in the list), each line containing two anagrammatic phrases separated by ‘=’.
    Each anagram pair should be printed exactly once, and the order of the two phrases within a printed pair must be lexicographic, as well as the first phrases and the second ones in case some first are equal.
    Two consecutive outputs for two consecutive input cases are separated by a single blank line.
Sample Input
1

carthorse
horse
horse cart
i do not know u
ok i now donut
orchestra
Sample Output
carthorse = horse cart
carthorse = orchestra
horse cart = orchestra
i do not know u = ok i now donut

问题链接:UVA454 Anagrams
问题简述:(略)
问题分析
    给定若干字符串,输出若干字符串组,其字母组成是相同的,用等号连接起来输出。
    简单题不解释。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA454 Anagrams */#include <bits/stdc++.h>using namespace std;int main()
{string line;int t;cin >> t;cin.ignore();cin.ignore();while(t--) {set<pair<string, string> > s;while(getline(cin, line) && line != "") {string t = "";for(int i = 0; line[i]; i++)if(!isspace(line[i]))t += line[i];sort(t.begin(), t.end());s.insert(make_pair(line, t));}for(set<pair<string, string> >::iterator iter1 = s.begin(); iter1 != s.end(); iter1++) {set<pair<string, string> >::iterator iter2 = iter1;for(iter2++; iter2 != s.end(); iter2++)if(iter1->first != iter2->first && iter1->second == iter2->second)cout << iter1->first << " = " << iter2->first << endl;}if(t) cout << endl;}return 0;
}

UVA454 Anagrams【set+排序】相关推荐

  1. Competitive Programming 3题解

    题目一览: Competitive Programming 3: The New Lower Bound of Programming Contests(1) Competitive Programm ...

  2. [CareerCup] 11.2 Sort Anagrams Array 异位词数组排序

    11.2 Write a method to sort an array of strings so that all the anagrams are next to each other. 这道题 ...

  3. LeetCode Anagrams

    Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be ...

  4. group anagrams leetcode java_LeetCode第[49]题(Java):Group Anagrams

    题目:同字符分组 难度:Medium 题目内容: Given an array of strings, group anagrams together. 翻译:给定一组字符串数组,按相同字符组成的字符 ...

  5. LeetCode 49 Group Anagrams(字符串分组)

    题目链接: https://leetcode.com/problems/anagrams/?tab=Description Problem:给一个字符串数组,将其中的每个字符串进行分组,要求每个分组中 ...

  6. Two Strings Are Anagrams

    Write a method anagram(s,t) to decide if two strings are anagrams or not. Example Given s="abcd ...

  7. 对anagrams分组 Group Anagrams

    为什么80%的码农都做不了架构师?>>>    问题: Given an array of strings, group anagrams together. For example ...

  8. LeetCode 49. Group Anagrams

    Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...

  9. 【LeetCode】49. Group Anagrams

    题目: Given an array of strings, group anagrams together. For example, given: ["eat", " ...

最新文章

  1. hadoop学习--多表关联
  2. MySQL——基于CASE WHEN的常用查询
  3. 浅析Java各种变量线程安全问题
  4. python中集合所用的reduce_Python中reduce函数和lambda表达式的学习
  5. iOS 常用公共方法
  6. JAVA圣诞代码,圣诞节(示例代码)
  7. IT 事业发展:树立自己的品牌
  8. CC++运算符优先级
  9. orm2 中文文档 4.3 extendsTo(一对一关系)
  10. linux下安装配置svn独立服务器
  11. delphi7中idHTTP的使用
  12. 机器学习之旅:支持向量机通俗导论(理解SVM的三层境界)
  13. c 语言全局变量的声明及用法,《c语言全局变量的用法》
  14. 第一台计算机英语句子,20个虚拟语气句子带翻译
  15. 基于Echarts实现可视化数据大屏物流云大数据看板页面HTML模板
  16. ‘latin-1‘ codec can‘t encode characters in position 5-17: ordinal not in range(256) 在请求数据的时候提示报错
  17. 测试wince wifi漫游的方法(参考)
  18. 华为HCIA考试全解答
  19. C-V2X 与智能车路协同技术 的深度融合
  20. proto-buf模型格式测试一例

热门文章

  1. 修改GDAL库支持RPC像方改正模型
  2. mysqli_connect参数的写法以及如何设置特定端口
  3. 二进制方式搭建极简kubernetes1.10环境@centos7.3
  4. Android 获取唯一机器码的代码
  5. 移动开发平台收入对比
  6. commons-fileupload 上传图片路径到mysql_上传图片到服务器并将图片路径保存到数据库...
  7. 【java学习之路】(javaWeb篇)008.VUE
  8. 上海交大计算机专硕学费2018,2018年上海交通大学博士研究生学费与相关奖助政策...
  9. java中的jni_JAVA中JNI的简单使用
  10. 每天Leetcode 刷题 初级算法篇-数学问题-Fizz Buzz