Hzu挑战自我


私信TA

用户名:gxhzxyjsj

访问量:90743

签 名:

2023终究会过去,期待2024!

等  级
排  名 8
经  验 26241
参赛次数 58
文章发表 157
年  龄 0
在职情况 教师
学  校 贺州学院
专  业 软件工程

  自我简介:

弱鸡一个,继续努力!

解题思路: 按照题目意思,根据题目给出的函数完成相应的功能即可。


参考代码:

#include<iostream> 
#include<cstring> 
using  namespace  std; 
typedef struct   
{ 
	char name[21]; 
	char num[11]; 
	char sex; 
}Student; 

void readdata(Student stu[],int n) 
{ 
	for(int i=0;i<n;i++)
		cin>>stu[i].name>>stu[i].num>>stu[i].sex;
}

int findstudent(Student stu[],int n,char *data) 
{ 
	if (data==NULL) return -1;
	for(int i=0;i<n;i++)
	{
		if(strcmp(stu[i].name,data)==0 || strcmp(stu[i].num,data)==0)
			return i;
	}
	return -1;
} 

void solve(Student stu[],int n,int m) 
{ 
	char x[21],y[21];
	for(int i=0;i<m;i++)  
	{ 
		cin>>x>>y;
		int x_k=findstudent(stu,n,x);
		int y_k=findstudent(stu,n,y);
		if(x_k!=-1 && y_k!=-1)
		{
			if(stu[x_k].sex!=stu[y_k].sex)
				cout<<"Y"<<endl;
			else
				cout<<"N"<<endl;
		}
		else 
			cout<<"N"<<endl; 
	} 
} 

int main() 
{ 
	int n,m; 
	Student stu[1010];	
	cin>>n;	
	readdata(stu,n); 
	cin>>m; 
	solve(stu,n,m); 
	return 0;
}


 

0.0分

8 人评分

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

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区