解题思路:直接按题目意思写代码
注意事项:
参考代码:
#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 人评分
程序员的表白 (C语言代码)浏览:1471 |
Hello, world! (C语言代码)浏览:1201 |
最长单词 (C语言代码)浏览:1376 |
C语言训练-求1+2!+3!+...+N!的和 (C语言代码)浏览:789 |
文科生的悲哀 (C语言代码)浏览:1401 |
C语言程序设计教程(第三版)课后习题11.8 (C语言代码)浏览:695 |
Quadratic Equation (C语言代码)浏览:988 |
母牛的故事 (C语言代码)浏览:455 |
C语言程序设计教程(第三版)课后习题6.7 (C语言代码)浏览:598 |
纪念品分组 (C++代码)浏览:838 |