解题思路: 按照题目意思,根据题目给出的函数完成相应的功能即可。
参考代码:
#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 人评分
不容易系列2 (C语言代码)浏览:631 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:729 |
求组合数 (C语言代码)浏览:1195 |
C语言程序设计教程(第三版)课后习题8.4 (C语言代码)浏览:620 |
DNA (C语言代码)浏览:559 |
母牛的故事 (C语言代码)浏览:733 |
数组与指针的问题浏览:755 |
局部变量作函数返回值的问题浏览:1020 |
C语言程序设计教程(第三版)课后习题11.5 (C语言代码)浏览:1490 |
2006年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:375 |