北京师范大学珠海分校
Judge Online of ACM ICPC
1079 BNUEP的球迷
C语言版
Judge Online of ACM ICPC
1079 BNUEP的球迷
C语言版
- #include <stdio.h>
- #include <string.h>
- char x='A';
- struct team{
- char name[21];
- int score;
- int in;
- int out;
- }a[5];
- void reset(){
- int i;
- for (i=1;i<=4;i++){
- a[i].in=0;
- a[i].out=0;
- a[i].score=0;
- }
- }
- void input(){
- int i,x,y,t1hao,t2hao;
- char t1[21],t2[21];
- for (i=1;i<=4;i++) scanf("%s",&a[i].name);
- for (i=1;i<=6;i++){
- scanf("%s%s%d%d",&t1,&t2,&x,&y);
- t1hao=search(t1);
- t2hao=search(t2);
- a[t1hao].in+=x;
- a[t1hao].out+=y;
- a[t2hao].in+=y;
- a[t2hao].out+=x;
- if (x>y) a[t1hao].score+=3;
- else if (x==y){
- a[t1hao].score++;
- a[t2hao].score++;
- }
- }
- }
- int search(char x[]){
- int i;
- for (i=1;i<=4;i++)
- if (strcmp(x,a[i].name)==0) return i;
- }
- void swap(int i,int j){
- struct team tmp;
- tmp=a[i];
- a[i]=a[j];
- a[j]=tmp;
- }
- void sort(){
- int i,j;
- for (i=1;i<=4;i++)
- for (j=1;j<=4-i;j++){
- if (a[j].score<a[j+1].score) swap(j,j+1);
- if (a[j].score==a[j+1].score){
- if ((a[j].in-a[j].out)<(a[j+1].in-a[j+1].out)) swap(j,j+1);
- if ((a[j].in-a[j].out)==(a[j+1].in-a[j+1].out)){
- if (a[j].in<a[j+1].in) swap(j,j+1);
- }
- }
- }
- }
- void output(){
- printf("Group %c %s %s/n",x++,a[1].name,a[2].name);
- }
- int main(){
- int n;
- scanf("%d",&n);
- while(n--){
- reset();
- input();
- sort();
- output();
- }
- return 0;
- }