#include <iostream>
#include <map>
#include <list>
#include <string>
using namespace std;
struct BirthInfo
{
int month;
int day;
BirthInfo()
{
month = 0;
day = 0;
}
bool operator == (const BirthInfo& rhs ) const
{
if ( month == rhs.month && day == rhs.day )
{
return true;
}
return false;
}
bool operator < (const BirthInfo& rhs ) const
{
if ( month < rhs.month )
{
return true;
}
else if ( month == rhs.month )
{
if ( day < rhs.day )
{
return true;
}
}
return false;
}
};
struct SameBirthInfo
{
int nCount;
list<string> StrNoList;
SameBirthInfo()
{
nCount = 0;
}
};
typedef map<BirthInfo , SameBirthInfo> Result;
int main()
{
int nStudentCount = 0;
string strNo = "";
BirthInfo BirInfo;
Result result;
SameBirthInfo sameBirthInfo;
cin >> nStudentCount;
while( nStudentCount -- > 0 )
{
cin >> strNo >> BirInfo.month >> BirInfo.day;
Result::iterator iter = result.find( BirInfo );
if ( iter == result.end() )
{
//找不到
pair<Result::iterator , bool> pInsRet = result.insert( Result::value_type(BirInfo,sameBirthInfo) );
if ( pInsRet.second )
{
pInsRet.first->second.nCount = 1; //记录下此生日有一人
pInsRet.first->second.StrNoList.push_back( strNo ); //记录下此人学号
}
}
else
{
//找到
iter->second.nCount++; //同一天生日人数++
iter->second.StrNoList.push_back( strNo ); //保存下这个学生的学号
}
}
//输出所有结果
Result::const_iterator cIter = result.begin();
while ( cIter != result.end() )
{
//先输出生日
cout << cIter->first.month << " " << cIter->first.day;
//输出所有学生学号
list<string>::const_iterator cStrIter = cIter->second.StrNoList.begin();
while ( cStrIter != cIter->second.StrNoList.end() )
{
cout << " " << cStrIter->c_str();
++cStrIter;
}
cout << endl;
++cIter;
}
return 0;
}
说几句无关的,我觉得写得有点问题,张亳豪你瞅一瞅,哪的问题
#include <map>
#include <list>
#include <string>
using namespace std;
struct BirthInfo
{
int month;
int day;
BirthInfo()
{
month = 0;
day = 0;
}
bool operator == (const BirthInfo& rhs ) const
{
if ( month == rhs.month && day == rhs.day )
{
return true;
}
return false;
}
bool operator < (const BirthInfo& rhs ) const
{
if ( month < rhs.month )
{
return true;
}
else if ( month == rhs.month )
{
if ( day < rhs.day )
{
return true;
}
}
return false;
}
};
struct SameBirthInfo
{
int nCount;
list<string> StrNoList;
SameBirthInfo()
{
nCount = 0;
}
};
typedef map<BirthInfo , SameBirthInfo> Result;
int main()
{
int nStudentCount = 0;
string strNo = "";
BirthInfo BirInfo;
Result result;
SameBirthInfo sameBirthInfo;
cin >> nStudentCount;
while( nStudentCount -- > 0 )
{
cin >> strNo >> BirInfo.month >> BirInfo.day;
Result::iterator iter = result.find( BirInfo );
if ( iter == result.end() )
{
//找不到
pair<Result::iterator , bool> pInsRet = result.insert( Result::value_type(BirInfo,sameBirthInfo) );
if ( pInsRet.second )
{
pInsRet.first->second.nCount = 1; //记录下此生日有一人
pInsRet.first->second.StrNoList.push_back( strNo ); //记录下此人学号
}
}
else
{
//找到
iter->second.nCount++; //同一天生日人数++
iter->second.StrNoList.push_back( strNo ); //保存下这个学生的学号
}
}
//输出所有结果
Result::const_iterator cIter = result.begin();
while ( cIter != result.end() )
{
//先输出生日
cout << cIter->first.month << " " << cIter->first.day;
//输出所有学生学号
list<string>::const_iterator cStrIter = cIter->second.StrNoList.begin();
while ( cStrIter != cIter->second.StrNoList.end() )
{
cout << " " << cStrIter->c_str();
++cStrIter;
}
cout << endl;
++cIter;
}
return 0;
}
说几句无关的,我觉得写得有点问题,张亳豪你瞅一瞅,哪的问题