UVA 10194 Football (aka Soccer) 足球成绩统计 检索+模拟

题意:先读入球队信息,再按“team_name_1#goals1@goals2#team_name_2”的格式读入球队的比赛情况,然后统计各个球队的比赛得分,进球数,丢球数等等各项指标。最后按题目给定的顺序输出各个球队的信息。

这题一个非常坑的地方就是在排序时队名的排序是按小写排的,看了别人博客上提醒才发现有这回事。。。

还有一个我被坑很久的就是球队的排序不是各指标全部都是从排的。。。这里wa无数次,实在令人羞愧。。。

这里读入球队信息的时候有个小trick,可以用scanf("%d@%d", &goals1, &goals2)这样去读入中间那快数据会更方便(虽然方便不了多少)。。。

代码:

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cctype>
using namespace std;

struct Table {
	int tp, g, w, t, l, h, i;
	string n;
}tb[50];

bool cmp(Table a, Table b) {
	if (a.tp != b.tp)
		return a.tp > b.tp;
	if (a.w != b.w)
		return a.w > b.w;
	if ((a.h - a.i) != (b.h - b.i))
		return (a.h - a.i) > (b.h - b.i);
	if (a.h != b.h)
		return a.h > b.h;
	if (a.g != b.g)
		return a.g < b.g;
	string ta, tb;
	for (int i = 0; i < a.n.size(); i++)
		ta += toupper(a.n[i]);
	for (int i = 0; i < b.n.size(); i++)
		tb += toupper(b.n[i]);
	return ta < tb;
}

int main() {
	int n;
	scanf("%d", &n);
	getchar();
	while (n--) {
		string name;
		int t, g;
		getline(cin, name);
		cout << name << endl;
		scanf("%d\n", &t);
		for (int i = 0; i < t; i++) {
			getline(cin, tb[i].n);
			tb[i].tp = tb[i].g = tb[i].w = tb[i].t = tb[i].l = tb[i].h = tb[i].i = 0;
		}
		scanf("%d\n", &g);
		for (int i = 0; i < g; i++) {
			string t1, t2;
			int n1, n2;
			int s1, s2;
			char tmp;
			while ((tmp = getchar()) != '#')
				t1 += tmp;
			scanf("%d@%d#", &s1, &s2);
			getline(cin, t2);
			for (int i = 0; i < t; i++)
				if (t1 == tb[i].n) {
					n1 = i;
					break;
				}
			for (int i = 0; i < t; i++)
				if (t2 == tb[i].n) {
					n2 = i;
					break;
				}
			//			cout << n1 << ' ' << s1 << ' ' << t1 << endl;
			//			cout << n2 << ' ' << s2 << ' ' << t2 << endl;
			tb[n1].g++;
			tb[n2].g++;
			tb[n1].h += s1;
			tb[n1].i += s2;
			tb[n2].h += s2;
			tb[n2].i += s1;
			if (s1 > s2) {
				tb[n1].tp += 3;
				tb[n1].w++;
				tb[n2].l++;
			}
			else if (s1 < s2) {
				tb[n2].tp += 3;
				tb[n2].w++;
				tb[n1].l++;
			}
			else {
				tb[n1].tp++;
				tb[n2].tp++;
				tb[n1].t++;
				tb[n2].t++;
			}
		}
		sort (tb, tb + t, cmp);
		for (int i = 0; i < t; i++) {
			printf("%d) ", i + 1);
			cout << tb[i].n;
			printf(" %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n", tb[i].tp, tb[i].g, tb[i].w, tb[i].t, tb[i].l, tb[i].h - tb[i].i, tb[i].h, tb[i].i);
		}
		if (n)
			cout << endl;
	}
	return 0;
}


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,这个问题涉及到C++编程语言中的格式化字符串和类型不匹配的问题。当使用格式化字符串时,需要确保格式化字符串中的类型与传递给它的参数的类型匹配。如果类型不匹配,就会出现"format specifies type 'unsigned int' but the argument has type 'char *'"这样的错误。 为了解决这个问题,你可以采取以下几种方法: 1. 确保格式化字符串中的类型与参数的类型匹配。在这种情况下,你需要将格式化字符串中的类型改为与参数的类型相匹配。例如,如果参数的类型是uint32_t*,你可以格式化字符串中的类型改为"%p"来打印指针的值。 2. 将参数的类型转换为与格式化字符串中的类型相匹配。在这种情况下,你可以使用类型转换操作符来将参数的类型转换为与格式化字符串中的类型相匹配。例如,如果参数的类型是char*,你可以使用"(unsigned int)"来将其转换为unsigned int类型。 3. 使用适当的格式化字符串和参数类型。在这种情况下,你需要根据参数的类型选择适当的格式化字符串。例如,如果参数的类型是unsigned int*,你可以使用"%u"来打印无符号整数的值。 下面是一个示例代码,演示了如何解决这个问题: ```cpp #include <iostream> #include <cstdint> int main() { uint32_t* ptr = nullptr; std::cout << "Pointer value: " << ptr << std::endl; // 输出:Pointer value: 0x0 std::cout << "Pointer address: " << (unsigned int)ptr << std::endl; // 输出:Pointer address: 0 return 0; } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值