bnu1079 BNUEP的球迷 C语言版

北京师范大学珠海分校
Judge Online of ACM ICPC
1079 BNUEP的球迷
C语言版
  1. #include <stdio.h>
  2. #include <string.h>

  3. char x='A';

  4. struct team{
  5.     char name[21];
  6.     int score;
  7.     int in;
  8.     int out;
  9. }a[5];

  10. void reset(){
  11.     int i;
  12.     for (i=1;i<=4;i++){
  13.         a[i].in=0;
  14.         a[i].out=0;
  15.         a[i].score=0;
  16.     }
  17. }

  18. void input(){
  19.     int i,x,y,t1hao,t2hao;
  20.     char t1[21],t2[21];
  21.     for (i=1;i<=4;i++) scanf("%s",&a[i].name);
  22.     for (i=1;i<=6;i++){
  23.         scanf("%s%s%d%d",&t1,&t2,&x,&y);
  24.         t1hao=search(t1);
  25.         t2hao=search(t2);
  26.         a[t1hao].in+=x;
  27.         a[t1hao].out+=y;
  28.         a[t2hao].in+=y;
  29.         a[t2hao].out+=x;
  30.         if (x>y) a[t1hao].score+=3;
  31.             else if (x==y){
  32.                 a[t1hao].score++;
  33.                 a[t2hao].score++;
  34.             }
  35.     }
  36. }

  37. int search(char x[]){
  38.     int i;
  39.     for (i=1;i<=4;i++)
  40.         if (strcmp(x,a[i].name)==0) return i;
  41. }

  42. void swap(int i,int j){
  43.     struct team tmp;
  44.     tmp=a[i];
  45.     a[i]=a[j];
  46.     a[j]=tmp;
  47. }

  48. void sort(){
  49.     int i,j;
  50.     for (i=1;i<=4;i++)
  51.         for (j=1;j<=4-i;j++){
  52.             if (a[j].score<a[j+1].score) swap(j,j+1);
  53.             if (a[j].score==a[j+1].score){
  54.                 if ((a[j].in-a[j].out)<(a[j+1].in-a[j+1].out)) swap(j,j+1);
  55.                 if ((a[j].in-a[j].out)==(a[j+1].in-a[j+1].out)){
  56.                     if (a[j].in<a[j+1].in) swap(j,j+1);
  57.                 }
  58.             }
  59.         }
  60. }

  61. void output(){
  62.     printf("Group %c %s %s/n",x++,a[1].name,a[2].name);
  63. }

  64. int main(){
  65.     int n;
  66.     scanf("%d",&n);
  67.     while(n--){
  68.         reset();
  69.         input();
  70.         sort();
  71.         output();
  72.     }
  73.     return 0;
  74. }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值