http://acm.hdu.edu.cn/showproblem.php?pid=1225

一道超级简单的题,就因为我忘记写return,就wa好久,拜托我自己细心一点。

学习的地方:不过怎么查找字符串并返回下标

Football Score

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2739    Accepted Submission(s): 785

Problem Description
Football is one of the greatest games in the world. Lots of people like to play football. After one season of matches, the header has to calculate the last scores of every team. He is too lazy that he doesn't want to calculate, so he asks you to write a program for him to solve the problem.

Here are the rules:
1 Every team has to match with all the other teams.
2 Every two teams have to match for two times,one at home and one away.
3 In one match, the winner will get 3 points, the loser will get 0 point. If it is draw, both of them will get 1 point.

 
Input
The input consists of many test cases. In each case, there will be a number N in the first line which means the number of teams. Followed by N * (N – 1)lines. Each line stands for a match between two teams. The format is: "Team1 VS Team2 p:q", p stands for the balls that Team1 has kicked in and q stands for the balls that Team2 has kicked in. p and q are not greater than 9.

Process to the end of file.

 
Output
For each test case, output the teams and their scores in descending order. One line a team, the format is: "TeamX scores". If two teams get the same score, the one with high net goals will be ahead, which net goal means the difference between the total balls that the team kicked in and the total balls that the team lost. IE: if one team kicked in 30 balls and lost 40 balls, then the net goal is 30 – 40 = -10. If two teams have the same score and the same net goal, the one whose kicked in balls is bigger will be ahead. If two teams have the same score and the same net goal and the same kicked in balls, they will be outputed in alphabetic order.

Output a blank line after each test case.

 
Sample Input
3
Manchester VS Portsmouth 3:0
Liverpool VS Manchester 1:1
Liverpool VS Portsmouth 0:0
Portsmouth VS Manchester 1:1
Manchester VS Liverpool 2:1
Liverpool VS Portsmouth 1:2
 
Sample Output
Manchester 8
Portsmouth 5
Liverpool 2

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int t;
struct node
{
char name[];
int kick;
int net;
int score;
}a[];
bool cmp(node b,node c)
{
if(b.score==c.score)
{
if(b.net==c.net)
{
if(b.kick==c.kick)
return strcmp(b.name,c.name)<?:; else
return b.kick>c.kick;
}
else
return b.net>c.net;
}
else
return b.score>c.score;
}
int find(char ss[]) //查找字符串并返回下标
{
int i;
if(t==-)
{
strcpy(a[].name,ss);
t=;
return t;
}
for(i=;i<=t;i++)
if(strcmp(a[i].name,ss)==)
return i;
t++;
strcpy(a[t].name,ss);
return t;
}
int main()
{
int n,i,x,y,p,q;
char str1[],str2[],str3[];
while(~scanf("%d",&n))
{
t=-;
memset(a,,sizeof(a));
for(i=;i<=n*(n-);i++)
{
scanf("%s",str1);
x=find(str1);
scanf("%s",str2);
scanf("%s",str3);
y=find(str3);
scanf("%d:%d",&p,&q);
a[x].kick+=p;
a[x].net+=p-q;
a[y].kick+=q;
a[y].net+=q-p;
if(p>q)
a[x].score+=;
else if(q>p)
a[y].score+=;
else
{
a[x].score+=;
a[y].score+=;
}
}
sort(a,a+t+,cmp);
for(i=;i<=t;i++)
{
printf("%s %d\n",a[i].name,a[i].score); }
printf("\n"); }
return ;
}

HDU-1225 Football Score的更多相关文章

  1. 【HDOJ】1225 Football Score

    这种结构体排序的题,十分容易考上机题,qsort+结构体解决.马上就要机考了,多练习一下这样的题目也好. #include <stdio.h> #include <string.h& ...

  2. HDU 5873 Football Games 【模拟】 (2016 ACM/ICPC Asia Regional Dalian Online)

    Football Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  3. HDOJ(HDU) 2309 ICPC Score Totalizer Software(求平均值)

    Problem Description The International Clown and Pierrot Competition (ICPC), is one of the most disti ...

  4. HDU 5873 Football Games(竞赛图兰道定理)

    http://acm.hdu.edu.cn/showproblem.php?pid=5873 题意: 现在有比赛,所有队伍两两进行比赛,赢的积2分,输的积0分,如果平局的话就各自都积1分,现在给出每只 ...

  5. HDU-1225 Football Score 模拟问题(水题)

    题目链接:https://cn.vjudge.net/problem/HDU-1225 水题 代码 #include <algorithm> #include <string> ...

  6. HDU 5873 Football Games

    随便判了几个条件就过了,也不知道对不对的. 正解应该是: $[1].$${s_1} + {s_2} + {s_3} + ...... + {s_n} = n(n - 1)$ $[2].$${s_1} ...

  7. 2019的hdu暑假作业(欢迎纠错)

    1219 遍历计数. #include<bits/stdc++.h> #define QAQ 0 using namespace std; ]; ]; int main(){ )){ me ...

  8. CHAPTER 40 Science in Our Digital Age 第40章 我们数字时代的科学

    CHAPTER 40 Science in Our Digital Age 第40章 我们数字时代的科学 The next time you switch on your computer, you ...

  9. 2019.12.12 Java的多线程&匿名类

    Java基础(深入了解概念为主) 匿名类 定义 Java匿名类很像局部或内联系,只是没有明细.我们可以利用匿名类,同时定义并实例化一个类.只有局部类仅被使用一次时才应该这么做. 匿名类不能有显式定义的 ...

随机推荐

  1. [压缩解压缩] SharpZip--压缩、解压缩帮助类

    里面有三个类都是用于压缩和解压缩的.大家看下图片 看下面代码吧 /// <summary> /// 类说明:SharpZip /// 编 码 人:苏飞 /// 联系方式:361983679 ...

  2. latch:cache buffers chains的优化思路

    数据块在buffer cache存放是以linked list方式存放的.当一个session想要访问/修改buffer cache的block,首先需要通过hash算法检查该block是否存在于bu ...

  3. hibernate 连接 oracle数据库

    前言:以下所有的操作都是基于你已经成功安装了oracle数据库并且java的开发环境正常的情况下进行的. 如果没有完善请先配置基础环境. 第一步:配置需要的环境(下载并导入需要的包). 我的百度云盘里 ...

  4. prime,素数的判断——c语言

    输入一个数a,求他是否是素数(用函数) 程序: #include<stdio.h> int prime(int a)-----------------------------------/ ...

  5. Vim自动补全神器:YouCompleteMe(转)

    转自:http://blog.jobbole.com/58978/ 可能会有一段时间写linxu,免不了用vim,留着,找时间实操之 原文出处: marchtea 的博客 第一次听说这个插件还是在偶然 ...

  6. Ninject 自动注册

    首先这个问题我纠结了很久,看到autofac强大的自动注册功能,我感觉Ninject弱爆了,不过Ninject自带属性注册,感觉很方便,所以还在纠结Ninject 传统的绑定方式 public cla ...

  7. JavaScript学习心得(五)

    一时间 1970年1月1日是电脑常用的时间参考点,称为纪元(Epoch)或者UNIX时间戳(UNIX Epoch).JavaScript中的Date对象能够表示1970年1月1日子夜前后1亿天之内的任 ...

  8. MYSQL 错误 :Out of resources when opening file './datagather/mx_domain#P#p178.MYD' (Errcode: 24) 解决办法

    出现Out of resources when opening file './xxx.MYD' (Errcode: 24)错误是因为打开的文件数超过了my.cnf的--open-files-limi ...

  9. uboot的mtd功能支持

    一.概述 1.MTD MTD是Flash的一种管理方法,将Flash划分成几个分区,便于管理. u-boot的MTD功能是在文件cmd_jffs2.c中实现的,由此我们可以知道怎样打开u-boot的M ...

  10. C#反射(二) 【转】

    如果没有看<C#反射(一)>.建议先看<C#反射(一)>再看这一篇.上一篇文章发表,有人评论我所写的东西比较基础.其实我也知道我也只不过是在写最基础的语法而已,之所以写它是因为 ...