nyoj——675 Sinking Ship
来源:互联网 发布:mac sass安装教程 编辑:程序博客网 时间:2024/04/28 02:26
Sinking Ship
- 描述
- The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should 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 should 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.
- 输入
- The first line contains an integer n, which is the number of people in the crew (1 ≤ n ≤ 100). Then follow n lines. The i-th of those lines contains two words — the name of the crew member who is i-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 for a rat, woman for a woman, childfor a child, man for a man, captain for the captain. The crew contains exactly one captain.
- 输出
- Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship.
- 样例输入
6Jack captainAlice womanCharlie manTeddy ratBob childJulia woman
- 样例输出
TeddyAliceBobJuliaCharlieJack
- 来源
NYIST第一届校赛(专业组)
题意:船将要下沉,为了使船上的人安全逃生,逃离人员的顺序如下:第一批逃跑的是rat,妇女和孩子的优先级相同,所以第二批逃跑的人为woman和child,第三批逃跑的人为man,最后一批为船上captain。输入的情况是前面为人名,空格后面为属于哪一类。
由于数据较少,所以在这里对几种情况分开讨论,用三维数组尝试了下,直接水过了。
代码:
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define N(n,m) memset(n,m,sizeof(n));
#define M(n,m,k) for(int n=m;n<k;n++)
using namespace std;
char a[101][2][11];
int main()
{
int t;
while(scanf("%d",&t)!=EOF)
{
N(a,0)
for(int i=0; i<t; i++)
{
cin>>a[i][0]>>a[i][1];
}
for(int i=0; i<t; i++)
if(strcmp(a[i][1],"rat")==0)
{
a[i][1][0]='^';
printf("%s\n",a[i][0]);
}
for(int i=0; i<t; i++)
if(a[i][1][0]!='^')
if(strcmp(a[i][1],"woman")==0||strcmp(a[i][1],"child")==0)
{
a[i][1][0]='^';
printf("%s\n",a[i][0]);
}
for(int i=0; i<t; i++)
if(a[i][1][0]!='^')
if(strcmp(a[i][1],"man")==0)
{
a[i][1][0]='^';
printf("%s\n",a[i][0]);
}
for(int i=0; i<t; i++)
if(a[i][1][0]!='^')
printf("%s\n",a[i][0]);
}
return 0;
}
- nyoj——675 Sinking Ship
- NYOJ 675 Sinking Ship
- A. Sinking Ship
- CF:63A. Sinking Ship
- 【水分类】#59 A. Sinking Ship
- A captain would never run away from his duty, if he knew the ship was sinking.
- 从零开始Desire HD刷机指南 —— 第八章:把手机由SHIP S-ON 变为SHIP S-OFF
- Mandelbrot集的最新变化形态一览——MandelBox,Mandelbulb,Burning Ship,NebulaBrot
- U3d插件——Swarm Object Manager分析(一)Main和 ship(角色)
- Debug Assertion Failed!——File:\dd\vctools\vc7libs\ship\atlmfc\include\afxwin1.inl
- Mandelbrot集的最新变化形态一览——MandelBox,Mandelbulb,Burning Ship,NebulaBrot
- model-ship ship-crafts
- 从零开始Desire HD刷机指南 —— 第七章:详解SHIP ENG S-ON S-OFF
- Asia's sinking economies
- ship shell
- hdu5093battle ship
- NYOJ——17
- NYOJ——71
- Agile——敏捷开发
- 排序
- 多段图的最短路径问题
- 设计模式
- android 通过浏览器url打开app的设置方法
- nyoj——675 Sinking Ship
- Win7 保存cookies位置
- Android官网Activities文档翻译
- Struts2中过滤器和拦截器的区别
- Could not transfer artifact *************** from/to central (http://repo1.maven.org/maven2
- Java中Map、Set集合的遍历
- CSDN客服好给力
- WinForm中异步执行任务实例-按回车异步执行各任务。
- C# ASP.NET 后台界面加载时调用前台JavaScript脚本:Attributes.Add()