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 ...
随机推荐
- (转载) popupWindow 指定位置上的显示
popupWindow 指定位置上的显示 标签: androidpopupWindowpopupWindow具体位置放置 2014-07-09 16:23 1114人阅读 评论(0) 收藏 举报 分 ...
- C#监测方法执行效率
System.Diagnostics.Stopwatch watch = new Stopwatch(); watch.Start(); // 开始监视代码运行时间 //需要监测的代码 dothing ...
- SurfaceView加载长图
1:SurfaceView加载长图,移到.可以充当背景 效果截图 2:View (淡入淡出动画没实现:记录下) package com.guoxw.surfaceviewimage; import a ...
- FLP不可能原理
1. FLP impossibility背景 FLP Impossibility(FLP不可能性)是分布式领域中一个非常著名的结果,该结果在专业领域被称为“定理”,其地位之高可见一斑.该定理的论文是由 ...
- java控制台输入输出字符串
一.实例说明 本实例通过输入流(System.in)实现从控制台接受用户输入信息,并将该信息输出到控制台. 运行效果如下图: 二.实现代码 三.要点说明 该实例的关键就是用到了System类的输入流, ...
- 洛谷P1120 小木棍 [数据加强版]搜索
玄学剪支,正好复习一下搜索 感觉搜索题的套路就是先把整体框架打出来,然后再一步一步优化剪枝 1.从maxv到sumv/2枚举长度(想一想,为什么) 2. 开一个桶,从大到小开始枚举 3. 在搜索中,枚 ...
- 网络教程(10)回顾ARP和ping数据包
Ping 192.168.20.2 ICMP Echo (Internet Control Message Protocol ICMP Echo request ICMP Echo reply 收到I ...
- BZOJ 3434 [WC2014]时空穿梭 (莫比乌斯反演)
题面:BZOJ传送门 洛谷传送门 好难啊..反演的终极题目 首先,本题的突破口在于直线的性质.不论是几维的空间,两点一定能确定一条直线 选取两个点作为最左下和最右上的点! 假设现在是二维空间,选取了$ ...
- 基于Vue的事件响应式进度条组件
写在前面 找了很多Vue 进度条组件!,都不包含拖拽和点击事件,input range倒是原生包含input和change事件,但是直接基于input range做进度条的话,样式部分需要做大量调整和 ...
- bitset骚操作
bitset的用途挺多的,是一个比较骚的常数优化 一.很多位数的二进制数 poj 2443 http://poj.org/problem?id=2443 直接开个1万位的二进制数,求交就行了. 有关集 ...