入门模拟——A1036.Boys vs Girls
#include <bits/stdc++.h> #include<math.h> using namespace std; struct Student{ char name[10]; char gender; char number[10]; int grade; }man,woman; const int MAX_LEN = 100005; int main(){ woman.gender = 'F'; woman.grade = -1; man.gender = 'M'; man.grade = 101; int n; cin>>n; for(int i = 0;i<n;++i){ Student temp; scanf("%s %s %s %d",&temp.name,&temp.gender,&temp.number,&temp.grade); if(temp.gender == 'F' && temp.grade > woman.grade){ memset(woman.name,'\0',sizeof(woman.name)); strcpy(woman.name,temp.name); memset(woman.number,'\0',sizeof(woman.number)); strcpy(woman.number,temp.number); woman.grade = temp.grade; } if(temp.gender == 'M' && temp.grade < man.grade){ memset(man.name,'\0',sizeof(man.name)); strcpy(man.name,temp.name); memset(man.number,'\0',sizeof(man.number)); strcpy(man.number,temp.number); man.grade = temp.grade; } } int count = abs(man.grade - woman.grade); if(woman.grade == -1){ printf("Absent\n"); }else{ cout<<woman.name<<" "<<woman.number<<endl; } if(man.grade == 101){ printf("Absent\n"); }else{ cout<<man.name<<" "<<man.number<<endl; } if(woman.grade == -1 || man.grade == 101){ printf("NA"); }else{ printf("%d",count); } system("pause"); return 0; }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步