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. 8.21 usaco

    summary:6 bzoj1692://后缀数组就行了O(nlogn)c[30]会RE...注意!!! #include<cstdio> #include<cstring> ...

  2. tyvj1161聚会的名单(trie树)

    背景 Background 明天就是candy的生日,candy又会邀请自己的一大堆好友来聚会了!哎!又要累坏飘飘乎居士了!! 描述 Description     明天就是candy的生日.晚上,c ...

  3. sql 的错误处理功能很弱

    --下面演示了SQL错误处理的脆弱性--邹建 --演示1--测试的存储过程1create proc p1asprint 12/0if @@error<>0print '发生错误1' sel ...

  4. UVA 1324 The Largest Clique 最大团(强连通分量,变形)

    题意:给一个有向图,要求找出一些点,使得这些点中的任意点对,要么可以互通,要么单向可达. 思路:最低只要求单向可达即可,即a->b都可以算进去. 强连通分量内的点肯定是满足要求的,可以全选,但是 ...

  5. 【转】禁止seekbar的拖动事件

    原文网址:http://blog.csdn.net/ansionnal/article/details/8229801 当然是可以的! 其实是 onTouchEvent 事件时,不让他传递事件就行了! ...

  6. WCF学习笔记(二):简单调用

    转:http://www.cnblogs.com/wengyuli/archive/2009/11/08/1598428.html 一个通信会话过程有两个部分组成,客户端和服务端,他们要进行会话就必然 ...

  7. JVM的GC机制及JVM的调优方法

    内存管理和垃圾回收是JVM非常关键的点,对Java性能的剖析而言,了解内存管理和垃圾回收的基本策略非常重要. 1.在程序运行过程当中,会创建大量的对象,这些对象,大部分是短周期的对象,小部分是长周期的 ...

  8. East Central North America Region 2015

    E 每过一秒,当前点会把它的值传递给所有相邻点,问t时刻该图的值 #include <iostream> #include <cstdio> #include <algo ...

  9. GCC编译源代码的四个步骤【转】

    GCC编译C源代码有四个步骤:预处理---->编译---->汇编---->链接. 可以利用GCC的参数来控制执行的过程,这样就可以更深入的了解编译C程序的过程. 下面将通过对一个程序 ...

  10. HW5.35

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...