#2398. 新生舞会

新生舞会

说明

&nbsp 算法训练&nbsp 新生舞会&nbsp  
时间限制:1.0s&nbsp  &nbsp 内存限制:512.0MB
 &nbsp  &nbsp
问题描述
  新生舞会开始了。n名新生每人有三个属性:姓名、学号、性别。其中,姓名用长度不超过20的仅由大小写字母构成的字符串表示,学号用长度不超过10的&nbsp 仅由数字构成的字符串表示,性别用一个大写字符‘F’或‘M’表示。任意两人的姓名、学号均互不相同。换言之,每个人可被其姓名或学号唯一确定。给出m对&nbsp 两人的信息(姓名或学号),判断他们是否能共舞。两人能共舞的充要条件为两人性别相异。

输入
  第一行一个整数n(2< =n< =1000),表示学生人数。接下来的n行每行依次包含一名新生的姓名、学号、性别,分别用一个空格隔开。
  之后的一行是一个整数m(1< =m< =1000),表示询问的数目。接着的m行每行包含两个信息(姓名或学号),保证两个信息不属于同一人,中间用一个空格隔开。

输出
  对于每个询问输出一行,如果两人可以共舞,输出一个大写字母‘Y’,否则输出一个大写字母‘N’。


样例输入
  4
  John&nbsp 10&nbsp M
  Jack&nbsp 11&nbsp M
  Kate&nbsp 20&nbsp F
  Jim&nbsp 21&nbsp M
  3
  John&nbsp 11
  20&nbsp Jack
  Jim&nbsp Jack


样例输出
  N
  Y
  N

提示
  可以把名字和学号都当成字符串处理。可以按以下流程实现。

  #include< iostream>
  #include< cstring>
  using&nbsp namespace&nbsp std;

  struct&nbsp tstudent
  {
  char&nbsp name[21];
  char&nbsp num[21];
  char&nbsp sex;
  };

  void&nbsp readdata(tstudent&nbsp student[],&nbsp int&nbsp n)
  {
输入N个学生的信息
  }

  int&nbsp findstudent(tstudent&nbsp student[],&nbsp int&nbsp n,&nbsp char*&nbsp data)
  {
  if&nbsp (data&nbsp ==&nbsp NULL)&nbsp return&nbsp -1;

判断是否有某个学生的学号或名字等于data,如果有,函数返回该学生在student数组中的序号,否则返回-1
  }

  void&nbsp solve(tstudent&nbsp student[],&nbsp int&nbsp n,&nbsp int&nbsp m)
  {
  char&nbsp x[21],&nbsp y[21];
  for&nbsp (int&nbsp i=0;&nbsp i< m;&nbsp i++)&nbsp {
输入两个人的信息X、Y。通过调用findstudent函数判断这两个人能否成为舞伴
  }
  }

  int&nbsp main()
  {
  int&nbsp n,&nbsp m;
  tstudent&nbsp student[1010];

  cin> > n;

  readdata(student,&nbsp n);
  cin> > m;
  solve(student,&nbsp n,&nbsp m);
  }

提示

请关注微信公众号onlinejudge