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. [.NET MVC进阶系列0x] EF Code First 数据迁徙(Migrations)

    [因] Entity Framework中使用Code First模式进行开发时,数据库是基于Models中的类自动生成的(生成时间:第一次运行MVC项目时), 每次更改Models中类结构,重新编译 ...

  2. 【jQuery日期处理】两个时间大小的比较

    function checkEndTime(){ var startTime=$("#startTime").val(); var start=new Date(startTime ...

  3. MongoDB之二基础入门(安装启动)

    mongodb中有三元素:数据库,集合,文档,其中“集合” 就是对应关系数据库中的“表”,“文档”对应“行”. 一. 下载 上MongoDB官网 ,我们发现有32bit和64bit,这个就要看你系统了 ...

  4. Breaking parallel loops in .NET C# using the Stop method z

    List<, , , , , , , , , }; Parallel.ForEach(integers, (int item, ParallelLoopState state) => { ...

  5. POJ 2828-Buy Tickets(线段树)

    题意: 有n个人,每人有一定的价值,给n个安排,每次安排有两个数 p,v p是这个人前面人的个数 (直接插在第p个人后面其他人后移),v是它的价值,n个安排后 求最终的价值序列. 分析: 越在后面的安 ...

  6. RhinoMocks简单范例

    using System; namespace MockTest { public interface IBBB { int Number { get; } int Compute(int j); i ...

  7. MSP430主系统时钟以及430的低功耗设置

    如何将系统时钟设置到外部高频晶体振荡器,430的MCLK默认的是DCO的,如何安全的从DCO切换到外部晶体振荡器,这是一个很重要的步骤,因为经过此步骤,可以极大地提高430的处理能力,DCO在内部,可 ...

  8. 9.19AD和DA操作

    下载芯片说明书的网站:http://www.21ic.com/ D/A digital是数字信号,analog是模拟信号,单片机属于数字芯片,内部只有0和1,这两种信息无法表示一个模拟量,如果是一个8 ...

  9. 配置OpenGL及第一个实例

    Windows环境下安装GLUT的步骤:1.将下载的压缩包解开,将得到5个文件2.在“我的电脑”中搜索“gl.h”,并找到其所在文件夹(如果是VS,则应该是其安装目录下面的“VC\PlatformSD ...

  10. 【暑假】[深入动态规划]UVa 1412 Fund Management

    UVa 1412 Fund Management 题目: UVA - 1412 Fund Management Time Limit: 3000MS   Memory Limit: Unknown   ...