HDU2093
较难,知识点较多
1.iosmanip deshiyong
2.sort排序的使用
3.多练习
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;
struct person{
string name;
int time;
int punish;
}persons[1000];
int change(string time, int m)
{
int ans = 0, minus = 0;
bool flag = true;
if(time[0] == '-' || time[0] == '0')
return 0;
else
{
for(auto c:time)
{
if(c == '('||c == ')')
{
flag = false;
}
else
{
if(flag)
{
ans = ans * 10 + (c - '0');
}
else
{
minus = minus * 10 + (c - '0');
}
}
}
return ans + minus * m;
}
}
int cmp(person a, person b)
{
if(a.time != b.time)
return (a.time > b.time);
else if(a.punish != b.punish)
return (a.punish < b.punish);
else
{
return a.name < b.name;
}
}
int main()
{
int a, b;
cin>>a>>b;
string inf, word, time;
int num = -1;
while(getline(cin, inf))
{
++num;
persons[num].punish = 0;
persons[num].time = 0;
cin>>persons[num].name;
for(int i = 0; i < a; ++i)
{
cin>>time;
if(!(time[0] == '0' || time[0] == '-'))
++persons[num].time;
persons[num].punish += change(time, b);
}
}
sort(persons,persons + num, cmp);
for(int i = 0; i < num ; ++i)
{
cout<<setw(10)<<left<<persons[i].name<<" "<<setw(2)<<right<<persons[i].time<<" "<<setw(4)<<right<<persons[i].punish<<endl;
}
return 0;
}