At the start of each school year, a very important event happens at Hogwarts. Each of the first-year wizards and witches is assigned to one of the four Hogwarts houses. The bravest children are put
to Gryffindor, the cleverest are put to Ravenclaw, the most hard-working go to Hufflepuff, and Slytherin becomes home to the most ambitious. The assignment is carried out in the Great Hall of Hogwarts castle in the following way: when the name of a first-year
student is called, he or she comes out to the center of the Hall and puts on the famous Sorting Hat. The Hat estimates the situation in the head of the young wizard or witch and cries out the name of the house to which the student is assigned. A special elf
writes down the Hat's decisions. After the sorting, the elf must quickly compile lists of students of each house. Members of the Society for the Promotion of Elfish Welfare beg you to help the elf in this hard work.

Input

The first line contains the number of first-year students N (1 ≤ N ≤ 1000). In the next 2N lines there are their names followed by houses in which the Sorting Hat placed them.
A student's name may contain lowercase and uppercase English letters, spaces and hyphens. Each name contains not more than 200 symbols.

Output

Output lists of students of each house in the following format. In the first line there is the name of the house, then a colon, and in the next lines there is the list of students, one in a line. The
lists must be given in the following order: Slytherin, Hufflepuff, Gryffindor, Ravenclaw. There must be empty lines between the lists. In each list, names must be given in the order in which they were called out during the sorting. It is guaranteed that each
list will contain at least one student.

Sample

input output
7
Ivan Ivanov
Gryffindor
Mac Go Nagolo
Hufflepuff
Zlobeus Zlei
Slytherin
Um Bridge
Slytherin
Tatiana Henrihovna Grotter
Ravenclaw
Garry Potnyj
Gryffindor
Herr Mionag-Ranger
Gryffindor
Slytherin:
Zlobeus Zlei
Um Bridge Hufflepuff:
Mac Go Nagolo Gryffindor:
Ivan Ivanov
Garry Potnyj
Herr Mionag-Ranger Ravenclaw:
Tatiana Henrihovna Grotter

这是个利用map来分类的问题。

注意一下getline的运用,会把之前遗漏下来的换行符都继续读取的,所以记得要去掉之前有输入而又不使用getline读入的换行符。

利用一个数据结构:unordered_map<string, vector<string>>就能解决这个问题了

#include <string>
#include <vector>
#include <iostream>
#include <unordered_map>
using namespace std; namespace{ static const int HOUSES = 4;
string houses[HOUSES] = {"Slytherin","Hufflepuff","Gryffindor","Ravenclaw"}; } void SortingHat1446()
{
int n = 0;
cin>>n; string name, houseName;
cin.ignore();//注意:去掉这个dumb换行符 unordered_map<string, vector<string> > umSVS;
for (int i = 0; i < n; i++)
{
getline(cin, name);
getline(cin, houseName);
umSVS[houseName].push_back(name);
}
for (int i = 0; i < HOUSES; i++)
{
vector<string> tmp = umSVS[houses[i]];
cout<<houses[i]<<":\n";
for (int j = 0; j < (int)tmp.size(); j++)
{
cout<<tmp[j]<<endl;
}
cout<<endl;
}
}
int main()
{
SortingHat1446();
return 0;
}

Timus 1446. Sorting Hat 分类问题的更多相关文章

  1. Codeforces - 65D - Harry Potter and the Sorting Hat - 简单搜索

    https://codeforces.com/problemset/problem/65/D 哈利波特!一种新思路的状压记忆化dfs,记得每次dfs用完要减回去.而且一定是要在dfs外部进行加减!防止 ...

  2. python streamlit 速成web页面,深度学习模型展示.

    #  点我查看 参考文献 py中一个web应用,Streamlit 是一个开源 Python 库,可让您轻松创建和共享用于机器学习和数据科学的精美自定义 Web 应用程序.只需几分钟,您就可以构建和部 ...

  3. DNA Sorting 分类: POJ 2015-06-23 20:24 9人阅读 评论(0) 收藏

    DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 88690 Accepted: 35644 Descrip ...

  4. URAL(timus) 1280 Topological Sorting(模拟)

    Topological Sorting Time limit: 1.0 secondMemory limit: 64 MB Michael wants to win the world champio ...

  5. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  6. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  7. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  8. POJ 题目分类(转载)

    Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...

  9. (转)POJ题目分类

    初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推. ...

随机推荐

  1. BZOJ2140: 稳定婚姻

    题解: 题意就是求二分图的必须边. 我们有结论: 在残量网络上跑tarjan,对于一条边(u,v) 如果该边满流||scc[u]==scc[v],那么该边是可行边. 因为如果scc[u]==scc[v ...

  2. postgresql 行转列,拼接字符串

    create table k_user ( op_id ) not null, op_name ) not null, password ) not null, real_name ) not nul ...

  3. pt-table-checksum 主从复制一致性检查

    1. pt-table-checksum介绍 http://www.percona.com/doc/percona-toolkit/2.2/pt-table-checksum.html pt-tabl ...

  4. C# 两个ListBox 数据互传-基础操作

    先看效果图: 两个服务设施列,左边:lbFacility1,右边:lbFacility2,中间向左向右箭头. 如果只是单纯的向左向右移动,那很简单. 因为项目遇到要获取选中项的ID,通过给ListBo ...

  5. java 多线程下载

    import java.io.ByteArrayOutputStream; import java.io.InputStream; public class StreamTool { /** * 把一 ...

  6. HDU 5536 Chip Factory 字典树+贪心

    给你n个数,a1....an,求(ai+aj)^ak最大的值,i不等于j不等于k 思路:先建字典树,暴力i,j每次删除他们,然后贪心找k,再恢复i,j,每次和答案取较大的,就是答案,有关异或的貌似很多 ...

  7. Java面试题:n=2\n1*2*5*6\n--3*4\n\nn=3\n1*2*3*10*11*12\n--4*5*8*9\n----6*7\n如何实现如上结构的数据

    今天学长在面试的时候遇到了一道题,然后让大家做一做. 在不看下面的答案之前,悠闲的朋友们一起来抖动一下大脑吧! 以下是我的想法: import java.util.Scanner;public cla ...

  8. MVC 实现计算页面执行时间

    使用 ActionFilterAttribute 来实现: public class PerformanceActionAttribute:ActionFilterAttribute { public ...

  9. .net之单元测试

    一.单元测试的目的是为了提高项目的质量 二..net单元测试的实施步骤是:在已经创建的类文件的某个方法上右键-->选择创建单元测试-->系统会创建单元测试解决方案--->单元测试解决 ...

  10. mvc5 HTML Helper

    转自:http://www.cnblogs.com/CodeFox/p/3782535.html 提及到HTML helper大家肯定不应该陌生, 因为在书写MVC View的时候肯定需要使用到它.一 ...