解题思路: 按照题目意思,根据题目给出的函数完成相应的功能即可。
参考代码:
#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 人评分
母牛的故事 (C语言代码)浏览:1300 |
上车人数 (C语言代码)浏览:781 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:751 |
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:545 |
WU-printf基础练习2 (C++代码)浏览:2007 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:542 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)from DQM浏览:671 |
字符逆序 (C语言代码)浏览:617 |
1014题解浏览:485 |
C语言程序设计教程(第三版)课后习题10.3 (C语言代码)浏览:1919 |