HD-ACM算法专攻系列(17)——考试排名

问题描述:

源码:

主要要注意输出格式.

#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;
}

  

时间: 2024-08-24 12:23:59

HD-ACM算法专攻系列(17)——考试排名的相关文章

HD-ACM算法专攻系列(23)——Crixalis&#39;s Equipment

题目描述: AC源码:此次考察贪心算法,解题思路:贪心的原则是使留下的空间最大,优先选择Bi与Ai差值最大的,至于为什么?这里用只有2个设备为例,(A1,B1)与(A2,B2),假设先搬运A1,搬运的那一瞬间,实际将要占用的空间应该为A1+B2,那么为了保证留下的空间最大,则应该有A1+B2<A2+B1成立,才能先搬运A1,即B1-A1>B2-B1.(n个设备可以两两做这样的比较,来达到选择的最优) #include"iostream" #include"algo

HD-ACM算法专攻系列(7)——排序

题目描述: 源码: #include"iostream" #include"string" using namespace std; void Order(int *p, int n) { int tmp; if(n < 2)return; for(int i = 0; i < n - 1; i++) { for(int j = 0; j < n - i - 1; j++) { if(p[j] > p[j + 1]) { tmp = p[j]

HD-ACM算法专攻系列(21)——Max Sum

问题描述: AC源码: 此题考察动态规划,解题思路:遍历(但有技巧),在于当前i各之和为负数时,直接选择以第i+1个为开头,在于当前i各之和为正数时,第i个可以不用作为开头(因为前i+1个之和一定大于第i+1个的值) #include"iostream" using namespace std; int main() { int t, n, start, end, sum, max, tmp; int a[100000]; scanf("%d", &t);

HD-ACM算法专攻系列(19)——七夕节

问题描述: AC源码: /**/ #include"iostream" #include"cmath" using namespace std; int main() { int t, n, sq, sum; scanf("%d", &t); for(int i = 0; i < t; i++) { scanf("%d", &n); sum = 1; sq = (int)sqrt(n); for(int

HD-ACM算法专攻系列(16)——find your present (2)

题目描述: 源码: #include"iostream" #include"string" using namespace std; bool IsFirstHalf(string *strs, int n, string str) { int count = 0; for(int i = 0; i < n; i++) { if(str < strs[i])count++; } return count >= (n / 2 + n % 2); }

HD-ACM算法专攻系列(14)——Quoit Design

问题描述: 源码: 经典问题--最近邻问题,标准解法 #include"iostream" #include"algorithm" #include"cmath" using namespace std; struct Point { double x; double y; }; Point S[100000];//不使用全局变量可能会超内存 bool cmpPointX(Point a, Point b) { return a.x > b

HD-ACM算法专攻系列(10)——大明A+B

题目描述: 源码: 需要注意的一点是输出是最简形式,需要去除小数的后导0,而调用stripTrailingZeros()函数后,数会以科学计数法输出,所以需要调用toPlainString(). import java.math.BigDecimal; import java.util.*; public class Main { //主函数 public static void main(String[] args) { BigDecimal a, b; Scanner cin = new S

HD-ACM算法专攻系列(4)——A == B ?

题目描述: 源码: /**/ #include"iostream" #include"string" using namespace std; string Standard(string str) { int start; int len = str.length(); char * p = new char[len + 2]; start = 0; if(str[0] == '-' || str[0] == '+') { p[0] = str[0]; start

算法研究,应付考试

package liu.jyc;public class Question { public static void main(String[] args) { fun(); public static void fun(){ String[] a = new String[17]; /// for(int i = 1;i<=9;i++){ a[2*(i-1)]=i+""; for(int j = 0;j<Math.pow(3, 8);j++){/// 一共有3^8种情况