1446. Sorting Hat
Time limit: 1.0 second
Memory limit: 64 MB
Memory limit: 64 MB
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 2
N 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 |
Problem Author: Stanislav Vasilyev
Problem Source: The Xth Urals Collegiate Programing Championship, March 24-25, 2006
Problem Source: The Xth Urals Collegiate Programing Championship, March 24-25, 2006
在霍格沃茨魔法学校里,有一顶分院帽。
一年级新生都要接受分院帽的分院,这将决定他们以后的生活和学习。
学院有4个,
格兰芬多(Gryffindor),
赫奇帕奇(Hufflepuff),
拉文克劳(Ravenclaw)
和斯莱特林(Slytherin)。
现在想让你帮忙统计分院的情况
一年级新生都要接受分院帽的分院,这将决定他们以后的生活和学习。
学院有4个,
格兰芬多(Gryffindor),
赫奇帕奇(Hufflepuff),
拉文克劳(Ravenclaw)
和斯莱特林(Slytherin)。
现在想让你帮忙统计分院的情况
#include <cstdio>
#include <cstdlib>
#include <cstring>
const int SNL[4]= {9,10,10,9};
const char SN[4][12]= {"Slytherin","Hufflepuff","Gryffindor","Ravenclaw"};
int n,length,tot[4]= {0},ans[4][1001];
char Student[1001][210],School[12];
bool CmpName(int x)
{
if (SNL[x] != length) return false;
for (int i=0; i<length; i++)
if (SN[x][i] != School[i])
return false;
return true;
}
int main()
{
scanf("%d%*c",&n);
for (int i=1; i<=n; i++)
{
memset(School,'\0',sizeof(School));
gets(&Student[i][0]);
gets(School);
length=strlen(School);
for (int j=0; j<4; j++)
if (CmpName(j))
{
ans[j][++tot[j]]=i;
break;
}
}
for (int i=0; i<4; i++)
{
printf("%s:\n",SN[i]);
for (int j=1; j<=tot[i]; j++)
puts(Student[ans[i][j]]);
printf("\n");
}
return 0;
}