杭电oj2093考试排名
题目直达 http://acm.hdu.edu.cn/showproblem.php?pid=2093
#include
#include
#include
#include
#include
using namespace std;
class Person
{
public:
string m_name;
int m_qesnum;
int m_time;
};
class Compare//自定义排序
{
public:
bool operator()(const Person& p1, const Person& p2) const
{
if (p1.m_qesnum == p2.m_qesnum)
{
if (p1.m_time == p2.m_time)
{
return p1.m_name < p2.m_name;
}
else return p1.m_time < p2.m_time;
}
else return p1.m_qesnum > p2.m_qesnum;
}
};
int StringToInt(string s)
{
int t;
stringstream ss(s);
ss >> t;
return t;
}
void ShowRand(multiset& ms)
{
for (multiset::iterator it = ms.begin(); it != ms.end(); it++)
{
cout << setw(10) << left << it->m_name << " " << setw(2) << right << it->m_qesnum
<< " " << setw(4) << right << it->m_time << endl;
}
}
int main()
{
int n, m;//题数 单位罚时
cin >> n >> m;
multiset ms;
string name;
while (cin>>name)//???如何停止循环
{
Person p;
p.m_name = name;
string record;//因为可能有括号用string不用int
int count = 0, time = 0;
for (int i = 0; i < n; i++)//记录每题的做题情况
{
cin >> record;
if (record[0] != '0' && record[0] != '-')
{
count++;//统计AC题数
int pos1 = record.find("(");//字符查找 未查找到返回-1
if (pos1 == -1)//无错误提交
{
time += StringToInt(record);
}
else//有错误提交 罚时
{
time += StringToInt(record.substr(0, pos1));
int pos2 = record.find(")");
string wrong = record.substr(pos1 + 1, pos2 - pos1 - 1);
time += StringToInt(wrong) * 20;
}
}
}
p.m_qesnum = count;
p.m_time = time;
ms.insert(p);
}
ShowRand(ms);
return 0;
}
Ctrl + z 键,输入结束直接回车即可结束while(cin>>name)循环。
把题目发出来