A. Sinking Ship

Source: Internet
Author: User
Time limit per test

2 seconds

Memory limit per test

256 megabytes

Input

Standard Input

Output

Standard output

The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. AllNCrew members have already lined up in a row (
Convenience Let's label them all from left to right with positive integers from 1N) And await further instructions. However, one shold
Evacuate the crew properly, in a strict order. Specifically:

The first crew members to leave the ship are rats. then women and children (both groups have the same priority) leave the ship. after that all men are evacuated from the ship. the Captain leaves the sinking ship last.

If we cannot determine exactly who shocould leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line
Is less ).

For each crew member we know his status as a crew member, and also his name. All crew members have different names. determine the order in which to evacuate the crew.

Input

The first line contains an integerN, Which is the number of people in the crew (1 limit ≤ limitNLimit ≤ limit 100 ).
Then followNLines.I-Th
Of those lines contains two words-the name of the crew member who isI-Th in line, and his status on the ship. The words are separated
By exactly one space. there are no other spaces in the line. the names consist of Latin letters, the first letter is uppercase, the rest are lowercase. the length of any name is from 1 to 10 characters. the status can have the following values: Rat
A rat, woman for a woman, child
A child, man for a man, Captain
The captain. The crew contains exactly one captain.

Output

PrintNLines.I-Th
Of them shoshould contain the name of the crew member who must beI-Th one to leave the ship.

Sample test (s) Input
6Jack captainAlice womanCharlie manTeddy ratBob childJulia woman
Output
TeddyAliceBobJuliaCharlieJack

Explanation: This question is actually a string output Problem in order. The question uses a description of the Titanic. First let rat (actually a mouse ?) Let's go, let the women and children go, and the captain goes to the end. We just need to remember these three types of people. Others must be between the women and the captain. You only need to set a tag for each string based on the identity, and then determine whether to output the tag.

#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include <algorithm>using namespace std;int main(){int n,i,a[105],j;char s[105][13],t[13];scanf("%d",&n);for(i=0;i<n;i++){scanf("%s %s",&s[i],&t);if(strcmp(t,"rat")==0){a[i]=0;printf("%s\n",s[i]);}else if(strcmp(t,"woman")==0||strcmp(t,"child")==0){a[i]=1;}else if(strcmp(t,"captain")==0){a[i]=3;}else{a[i]=2;}}for(j=1;j<=3;j++){for(i=0;i<n;i++){if(a[i]==j){printf("%s\n",s[i]);}}}return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.