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;
    }
    

      

    多学习,多总结。
  • 相关阅读:
    JNUOJ 1187
    JNUOJ 1184
    HDU 4848
    HDU 4849
    哈夫曼树和哈弗曼编码小记
    HDU 5726
    POJ 3368 & UVA 11235
    2016江苏省CPC省赛 I
    POJ 3928
    POJ 3067
  • 原文地址:https://www.cnblogs.com/yanhaiming/p/2818937.html
Copyright © 2011-2022 走看看