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. [GDI+] C# ImageClass帮助类教程与源码下载 (转载)

    点击下载 ImageClass.rar 功能如下图片 主要功能有:缩略图片,图片水印,文字水印,调整光暗,反色处理,浮雕处理,拉伸处理,左右翻转,上下翻转,压缩图片,图片灰度化,转换为黑白图片,获取图 ...

  2. C#将汉字转换成全拼的拼音EcanConvertToCh帮助类 (转)

    点击下载 EcanConvertToCh.rar 主要功能就是将汉字转换成全拼的拼音,只要你输入一个汉字就会相应的转成拼音 /// <summary> /// 编 码 人:苏飞 /// 联 ...

  3. ASCII 码表对照

    ASCII码表 ASCII码大致可以分作三部分组成.第一部分是:ASCII非打印控制字符第二部分是:ASCII打印字符:第三部分是:扩展ASCII打印字符 第一部分:ASCII非打印控制字符表 ASC ...

  4. CSS之关于clearfix--清除浮动

    一,什么是.clearfix 你只要到Google或者Baidu随便一搜"css清除浮动",就会发现很多网站都讲到"盒子清除内部浮动时可以用到.clearfix" ...

  5. Mac Zip命令

    mac终端命令 zip -[parameter] [yourName].zip someFileOrDiectory -q 表示不显示压缩进度状态 -r 表示子目录子文件全部压缩为zip //这部比较 ...

  6. Android学习笔记(SQLite的简单使用)

    1.SQLite介绍 SQLite,是一款轻型的数据库,是遵守ACID的关系型数据库管理系统,它包含在一个相对小的C库中.它是D.RichardHipp建立的公有领域项目.它的设计目标是嵌入式的,而且 ...

  7. codevs 4511 信息传递(NOIP2015 day1 T2)

    4511 信息传递 NOIP2015 day1 T2 时间限制: 1 s 空间限制: 128000 KB 传送门 题目描述 Description 有个同学(编号为 1 到)正在玩一个信息传递的游戏. ...

  8. 适合自己的vim配置文件

    主要用来写c++的:clang-completer这个是单独安装的,其他的都采用的vundle安装完成. clang-completer:只在centos7.2上安装成功过,6.4上失败了.先要安装一 ...

  9. NLPIR.user Not valid license or your license expired! Please feel free to contact pipy_zhang@msn.com

    NLPIR.user Not valid license or your license expired! Please feel free to contact pipy_zhang@msn.com ...

  10. WPF RadioButton & CheckBox Style

    <Style TargetType="CheckBox"> <Setter Property="Template"> <Sette ...