Algorithm training Freshman Prom

Source: Internet
Author: User
Tags uppercase character uppercase letter

algorithm training freshman Promtime limit: 1.0s memory limit: 512.0MB Problem Description
The freshman prom began. Each of the N freshmen has three attributes: Name, student number, gender. wherein, the name with a length of not more than 20 is composed of only uppercase and lowercase letters of the string representation, the study number is not more than 10 of the length of the number-only string representation, the gender with an uppercase character ' F ' or ' M ' representation. The names and school numbers of any two persons are different. In other words, each person can be uniquely identified by his or her name or school number. Give m information about two people (name or school number) to see if they can dance together. The necessary and sufficient conditions for the two men to dance are different from one sex to the other.

input
The first line is an integer n (2<=n<=1000), which indicates the number of students. The next n rows each row contains a new student's name, student number, and gender, separated by a single space.
The next line is an integer m (1<=m<=1000), which indicates the number of queries. The next M-line contains two messages (name or number), guaranteeing that two messages are not of the same person, separated by a space.

Output
For each query output line, if two people can dance together, output an uppercase letter ' Y ', otherwise output an uppercase letter ' N '.


Sample Input
4
John Ten M
Jack One M
Kate F
Jim M
3
John 11
Jack
Jim, Jack.


Sample Output
N
Y
N

Tips
You can treat both the name and the school number as strings. This can be achieved by following the process.

#include <iostream>
#include <cstring>
using namespace Std;

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

void ReadData (tstudent student[], int n)
{
Enter information for n students
}

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

determine if there is a student's number or name equals data, and if so, the function returns the number of the student in the student array, otherwise returns-1
}

void solve (tstudent student[], int n, int m)
{
Char x[21], y[21];
for (int i=0; i<m; i++) {
Enter information for two people x, Y. Determine if the two can be partners by calling the Findstudent function.
}
}

int main ()
{
int n, m;
Tstudent student[1010];

cin>>n;

ReadData (student, N);
cin>>m;
Solve (student, N, M);
}
class Student {    String name;    String Sno;    String sex;      Public Student (String name,string sno,string sex) {        this. name=name;          this. sno=Sno;         this. sex=sex;            }}
ImportJava.util.Scanner; Public classMain {Staticstudent stu[];  Public Static voidMain (string[] args) {//TODO auto-generated Method StubScanner sc=NewScanner (system.in);  while(Sc.hasnext ()) {intn=Sc.nextint (); Stu=NewStudent[n];  for(inti=0;i<n;i++) {String name=Sc.next (); String Sno=Sc.next (); String Sex=Sc.next (); Stu[i]=Newstudent (Name,sno,sex); }            intt=Sc.nextint ();  while(t-->0) {String tmp=Sc.next (); String TMP2=Sc.next (); String Sex1=""; String Sex2="";  for(inti=0;i<n;i++){                    if(Stu[i].name.equals (tmp) | |stu[i].sno.equals (TMP)) {Sex1=Stu[i].sex; }                    if(Stu[i].name.equals (TMP2) | |stu[i].sno.equals (TMP2)) {Sex2=Stu[i].sex; }                                    }                if(!sex1.equals (SEX2)) System.out.println (Y); ElseSystem.out.println (N);    }} sc.close (); }}

Algorithm training Freshman Prom

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.