HD-ACM算法专攻系列(16)——考试排名
问题描述:


源码:
主要要注意输出格式.
#include"iostream"
#include"iomanip"
#include"algorithm"
#include"string"
using namespace std; struct Person
{
string name;
int count;
int score;
}; bool cmp(Person a, Person b)
{
if(a.count > b.count)
{
return true;
}
else if(a.count == b.count)
{
if(a.score < b.score)
{
return true;
}
else if(a.score == b.score)
{
return a.name < b.name;
}
else
{
return false;
}
}
else
{
return false;
}
} int atoi(string str, int start, int end)
{
int result = 0;
for(int i = start; i <= end; i++)
{
result = result * 10 + (str[i] - '0');
}
return result;
} int main()
{
int n, m, index = 0;
string str;
Person *p = new Person[1000];
cin>>n>>m;
while(cin>>p[index].name)
{
p[index].count = 0;
p[index].score = 0;
for(int j = 0; j < n; j++)
{
cin>>str;
if(str[0] != '-' && str[0] != '0')
{
p[index].count++;
if(str[str.length() - 1] == ')')
{
for(int k = 0; k < str.length(); k++)
{
if(str[k] == '(')
{
p[index].score += atoi(str, 0, k - 1);
p[index].score += atoi(str, k+1, str.length() - 2) * m;
break;
}
}
}
else
{
p[index].score += atoi(str, 0, str.length() - 1);
}
}
}
index++;
//if(index == 6)break;
}
sort(p, p + index, cmp);
for(int i = 0; i < index; i++)
{ cout<<std::left<<setw(10)<<p[i].name<<" "<<std::right<<setw(2)<<p[i].count<<" "<<setw(4)<<p[i].score<<endl;
} return 0;
}
HD-ACM算法专攻系列(16)——考试排名的更多相关文章
- HD-ACM算法专攻系列(23)——Crixalis's Equipment
题目描述: AC源码:此次考察贪心算法,解题思路:贪心的原则是使留下的空间最大,优先选择Bi与Ai差值最大的,至于为什么?这里用只有2个设备为例,(A1,B1)与(A2,B2),假设先搬运A1,搬运的 ...
- HD-ACM算法专攻系列(21)——Wooden Sticks
题目描述: AC源码: 此题考查贪心算法,解题思路:首先使用快速排序,以w或l按升序排序(注意相等时,应按另一值升序排序),这样就将二维变量比较,变为了一维的,排好序的一边就不需要去管了,只需要对未排 ...
- HD-ACM算法专攻系列(22)——Max Sum
问题描述: AC源码: 此题考察动态规划,解题思路:遍历(但有技巧),在于当前i各之和为负数时,直接选择以第i+1个为开头,在于当前i各之和为正数时,第i个可以不用作为开头(因为前i+1个之和一定大于 ...
- HD-ACM算法专攻系列(20)——七夕节
问题描述: AC源码: /**/ #include"iostream" #include"cmath" using namespace std; int mai ...
- HD-ACM算法专攻系列(19)——Leftmost Digit
问题描述: AC源码: 解题关键是,数据很大,不能强算,需要使用技巧,这里使用科学计算法,令N^N=a*10^n ,取对数后变为 N*log10(N)=log10(a)+n,令x = log10(a) ...
- HD-ACM算法专攻系列(18)——Largest prime factor
题目描述: 源码: 需要注意,若使用cin,cout输入输出,会超时. #include"iostream" #include"memory.h" #defin ...
- HD-ACM算法专攻系列(17)——find your present (2)
题目描述: 源码: #include"iostream" #include"string" using namespace std; bool IsFirstH ...
- HD-ACM算法专攻系列(15)——Quoit Design
问题描述: 源码: 经典问题——最近邻问题,标准解法 #include"iostream" #include"algorithm" #include" ...
- HD-ACM算法专攻系列(14)——find your present (2)
问题描述: 源码: #include"iostream" #include"algorithm" using namespace std; bool cmp(i ...
随机推荐
- Python FLask 腾讯云服务器部署
CentOs 7.0云服务器部署Python Flask 使用: Python 2.7 Flask nginx gunicorn easy_install python-dev yum install ...
- Oracle"TNS监听程序找不到符合协议堆栈要求的可用处理程序"解决方案
问题描述:在使用ETL工具通过odbc方式连接Oracle进行数据抽取的过程中,Oracle 监听日志报错如下: 根本原因就是Oracle的process和session已经达到了甚至超过了最大值,解 ...
- vue2 阻止时间冒泡
click.stop.prevent <div class="content-right" @click.stop.prevent="pay" > ...
- adb使用实践
目录 1. adb 端口占用 2. 查看包名和MainAcitivity =============================================================== ...
- day06-08面向对象的三大特性
一.继承 1.1什么是继承?继承是一种创建新类的方式,在python中,新建的类可以继承一个或多个父类,父类又可称为基类或超类,新建的类称为派生类或子类python中类的继承分为:单继承和多继承 cl ...
- SciSharpCube:容器中的SciSharp,.NET机器学习开箱即用
SciSharp Cube 在Docker容器中快速体验SciSharp机器学习工具的最新功能. 项目地址:https://github.com/SciSharp/SciSharpCube 从Dock ...
- bzoj 1121: [POI2008]激光发射器SZK 思维_结论
Description 多边形相邻边垂直,边长为整数,边平行坐标轴.要在多边形的点上放一些激光发射器和接收器.满足下列要求: 1发射器和接收器不能放置在同一点: 2发射器发出激光可以沿壁反射,最终到达 ...
- POJ 2486 Apple Tree (树形dp 经典题)
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const ...
- BitmapMesh动画
一.概要 我们经常用到Canvas.drawBitmap方法,却很少用到Canvas.drawBitmapMesh方法.这个方法为我们做图片变形提供了无限可能,同时也对数学功底有较高的要求.下面先看一 ...
- django rest-farme-work 的使用(2)
serialization (序列化) 本测试项目例子地址为: tomchristie/rest-framework-tutorial 开始构建一个新的程序 创建一个新的环境 virtualenv e ...