时间有泪


私信TA

用户名:BrillianDiamond

访问量:647

签 名:

等  级
排  名 13779
经  验 859
参赛次数 2
文章发表 1
年  龄 0
在职情况 学生
学  校 北京大学
专  业

  自我简介:

解题思路:直接按题目意思写代码

注意事项:

参考代码:

#include<iostream>

#include<cstring>

using  namespace  std;


struct  tstudent

{

    char  name[21];

    char  num[21];

    char  sex;

};


void  readdata(tstudent  student[],  int  n)

{

    // 输入N个学生的信息

    for(int i=0; i<n; i++)

        cin>>student[i].name>>student[i].num>>student[i].sex;

}


int  findstudent(tstudent  student[],  int  n,  char*  data)

{

    if  (data  ==  NULL)

        return  -1;


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

    for(int i=0; i<n; i++)

    {

        if(strcmp(student[i].name,data)==0||strcmp(student[i].num,data)==0)

            return i;

    }

    return -1;


}


void  solve(tstudent  student[],  int  n,  int  m)

{

    char  x[21],  y[21];

    for  (int  i=0;  i< m;  i++)

    {

        //输入两个人的信息X、Y。通过调用findstudent函数判断这两个人能否成为舞伴

        cin>>x>>y;

        int x1=findstudent(student,n,x),y1=findstudent(student,n,y);

        if(x1>-1&&y1>-1&&x1!=y1&&student[x1].sex!=student[y1].sex)

            cout<<"Y"<<endl;

        else

            cout<<"N"<<endl;

    }

}


int  main()

{

    int  n,  m;

    tstudent  student[1010];


    cin>> n;


    readdata(student,  n);

    cin>> m;

    solve(student,  n,  m);

}

/**

4

John 10 M

Jack 11 M

Kate 20 F

Jim 21 M

3

John 11

20 Jack

Jim Jack

*/


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区