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. sqlserver 自定义字符串分割函数.

    --SQL Server Split函数 --Author: sq --说明:被分割后的字段为:short_str --支持分割符多字节 --使用方法 --Select * FROM splits(' ...

  2. java: Eclipse jsp tomcat 环境搭建(完整)

    ] 欢迎您! 要学习一门语言,首先要做的就是搭建环境,然后能写一个小的Demo(类似Helloworld),不仅可以建立信心,而且还可以为之后的学习搭建一个验证平台,事半功倍. net领域的vs,号称 ...

  3. (转)C# 中的委托和事件

    来源:http://www.tracefact.net/CSharp-Programming/Delegates-and-Events-In-CSharp.aspx 引言 委托 和 事件在 .Net ...

  4. 读取Excel异常定义了过多字段的解决方法

    /// <summary> /// 从Excel文件导入数据 /// </summary> /// <param name="ExcelStr"> ...

  5. android入门到熟练(一)

    1.andro系统架构:Linux内核层(提供驱动),系统运行库层和android运行时库(提供C/C++库的主要特性,如SQLite,OpenGL,Webkit等和Dalvik虚拟机),应用框架层, ...

  6. WPF提示框效果

    WPF提示框效果 1,新建WPF应用程序 2,添加用户控件Message 3,在Message中编写如下代码 <Border x:Name="border" BorderTh ...

  7. Android PackageManager packages.xml文件格式

    packages.xml文件存放在/data/system目录下    该文件记录了系统中所有应用程序的包管理相关信息    PmS根据该文件进行包管理的各种操作 标签名称 所包含的值举例 last- ...

  8. WPFDispatcher示例

    Dispatcher 类提供用于管理线程工作项队列的服务. 效果演示: <Window x:Class="WPF之Dispatcher对象.MainWindow" xmlns ...

  9. 黑马程序员——vim编辑器的使用

    ------Java培训.Android培训.iOS培训..Net培训.期待与您交流! ------- 一.基本操作 1.从命令提示符进入vim编辑器:   vim filename <ENTE ...

  10. Tomcat启动分析(Tomcat7.0)

    1)bin目录下的bootstrap.jar中的main方法启动Tomcat org.apache.catalina.startup.Bootstrap类下的main方法 可以看到Bootstrap类 ...