zoukankan      html  css  js  c++  java
  • PAT 1036. Boys vs Girls

    #include<iostream>
    #include<cstdio>
    #include<string>
    #include<cstring>
    #include<queue>
    #include<vector>
    #include<cmath>
    #include<iomanip>
    #include<algorithm>
    using namespace std;
    
    struct Student
    {
    	char chName[15];
    	char chId[15];
    	int iScore;
    };
    
    bool lessCmp(Student stu1, Student stu2)
    {
    	return stu1.iScore < stu2.iScore;
    }
    
    bool greaterCmp(Student stu1, Student stu2)
    {
    	return stu1.iScore > stu2.iScore;
    }
    
    int main()
    {
    	vector<Student> vBoys,vGirls;
    	int N,i;
    	char cGender;
    	Student stuTmp;
    	cin>>N;
    	for(i=0; i<N; i++)
    	{
    		cin>>stuTmp.chName>>cGender>>stuTmp.chId>>stuTmp.iScore;
    		if(cGender == 'M')
    			vBoys.push_back(stuTmp);
    		else
    			vGirls.push_back(stuTmp);
    	}
    	if(vGirls.size() == 0)
    		cout<<"Absent"<<endl;
    	else
    	{
    		sort(vGirls.begin(),vGirls.end(),greaterCmp);
    		cout<<vGirls[0].chName<<" "<<vGirls[0].chId<<endl;
    	}
    	if(vBoys.size() == 0)
    		cout<<"Absent"<<endl;
    	else
    	{
    		sort(vBoys.begin(),vBoys.end(),lessCmp);
    		cout<<vBoys[0].chName<<" "<<vBoys[0].chId<<endl;
    	}
    	if(vGirls.size() == 0 || vBoys.size() == 0)
    		cout<<"NA"<<endl;
    	else
    		cout<<vGirls[0].iScore-vBoys[0].iScore<<endl;
    	return 0;
    }
    

      

    多学习,多总结。
  • 相关阅读:
    mysql创建表
    MySql数据类型(转)
    mysql命令总结
    php文件遍历类:FileBianli.class.php
    php文件删除
    php文件复制
    php文件遍历
    php下载c
    智能眼镜的行业应用
    《代谢增长论》读书笔记
  • 原文地址:https://www.cnblogs.com/yanhaiming/p/2818937.html
Copyright © 2011-2022 走看看