Timus 1446. Sorting Hat 分类问题
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
A student's name may contain lowercase and uppercase English letters, spaces and hyphens. Each name contains not more than 200 symbols.
Output
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 |
Slytherin: |
这是个利用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 分类问题的更多相关文章
- Codeforces - 65D - Harry Potter and the Sorting Hat - 简单搜索
https://codeforces.com/problemset/problem/65/D 哈利波特!一种新思路的状压记忆化dfs,记得每次dfs用完要减回去.而且一定是要在dfs外部进行加减!防止 ...
- python streamlit 速成web页面,深度学习模型展示.
# 点我查看 参考文献 py中一个web应用,Streamlit 是一个开源 Python 库,可让您轻松创建和共享用于机器学习和数据科学的精美自定义 Web 应用程序.只需几分钟,您就可以构建和部 ...
- DNA Sorting 分类: POJ 2015-06-23 20:24 9人阅读 评论(0) 收藏
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 88690 Accepted: 35644 Descrip ...
- URAL(timus) 1280 Topological Sorting(模拟)
Topological Sorting Time limit: 1.0 secondMemory limit: 64 MB Michael wants to win the world champio ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- POJ 题目分类(转载)
Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...
- (转)POJ题目分类
初期:一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. ...
随机推荐
- [swustoj 679] Secret Code
Secret Code 问题描述 The Sarcophagus itself is locked by a secret numerical code. When somebody wants to ...
- RMAN备份与恢复深入解<一>
一 数据库版本 SQL> select *from v$version; BANNER ----------------------------------------------------- ...
- WCF 学习总结3 -- 实例模式
通过WCF的ServiceBehaviorAttribute设定InstanceContextMode有下面的3中模式: 1. Single —— 表示所有的客户端共享一个会话(服务对象)(服务关闭时 ...
- Fine Uploader文件上传组件
最近在处理后台数据时需要实现文件上传.考虑到对浏览器适配上采用Fine Uploader. Fine Uploader 采用ajax方式实现对文件上传.同时在浏览器中直接支持文件拖拽[对浏览器版本有要 ...
- ASDL + WN725N 配置无线AP
1. ASDL 正常拨号上网 2. 安装TP-LINK无线客户端应用程序 打开之后选择模拟AP 如下图设置----应用 3. 本地连接----属性----高级 如下图设置 4. 宽带连接--- ...
- 让你的.NET程序支持多语言
辛辛苦苦做出来的软件,我们当然希望能让更多的人用,支持多语言是必须的.下面我将以Asp.net Web Form为例来介绍如何支持多语言.其他程序比如windows程序,过程都是大同小异的. 大概分以 ...
- (一)NUnit单元测试心得
由于各种缘由,一本<.Net单元测试艺术>突然出现在了我的办公桌上,于是我的单元测试之路就此开始.通过一两个月不间断的学习,以及不断结合具体的项目做开发,再结合书上的知识对单元测试有了一些 ...
- 利用CryptoStream进行加密解密
public class DBSecurity { //sKey sIV这两个自己随意设定,不能外泄 private const string sKey = "11,22,33,43,34, ...
- C++&OpenCV中读取灰度图像到数组的两种
如标题所言,此处是对于灰度图像而言 ///method 1 read the image data one by one for (int row = 0, i = 0;row < imgDst ...
- 如何使用 SPICE client (virt-viewer) 来连接远程虚拟机桌面?
如何使用 SPICE client (virt-viewer) 来连接远程虚拟机桌面? 什么是SPICE? SPICE (Simple Protocol for Independent Computi ...