标签:hdu1225
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2579 Accepted Submission(s): 729
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
Manchester 8 Portsmouth 5 Liverpool 2Huge input, scanf is recommended.HintHint
#include <stdio.h> #include <string.h> #include <algorithm> using std::sort; struct Node{ char name[100]; int win, lost, points, net; } arr[1000]; int find(char str[], int k){ for(int i = 0; i < k; ++i) if(!strcmp(str, arr[i].name)) return i; return -1; } bool cmp(Node a, Node b){ if(a.points > b.points) return true; if(a.points == b.points && a.net > b.net) return true; if(a.points == b.points && a.net == b.net && a.win > b.win) return true; if(a.points == b.points && a.net == b.net && a.win == b.win && strcmp(a.name, b.name) < 0) return true; return false; } int main(){ int n, win, lost, pos, id, sign; char name1[100], name2[100]; while(scanf("%d", &n) == 1){ id = 0; for(int i = 0; i < n * (n - 1); ++i){ scanf("%s%*s%s %d:%d", name1, name2, &win, &lost); sign = win - lost; if((pos = find(name1, id)) != -1){ arr[pos].win += win; arr[pos].lost += lost; if(sign > 0) arr[pos].points += 3; else if(sign == 0) arr[pos].points += 1; }else{ strcpy(arr[id].name, name1); arr[id].win = win; arr[id].lost = lost; if(sign > 0) arr[id].points = 3; else if(sign == 0) arr[id].points = 1; else arr[id].points = 0; ++id; } if((pos = find(name2, id)) != -1){ arr[pos].win += lost; arr[pos].lost += win; if(sign < 0) arr[pos].points += 3; else if(sign == 0) arr[pos].points += 1; }else{ strcpy(arr[id].name, name2); arr[id].win = lost; arr[id].lost = win; if(sign < 0) arr[id].points = 3; else if(sign == 0) arr[id].points = 1; else arr[id].points = 0; ++id; } } for(int i = 0; i < n; ++i) arr[i].net = arr[i].win - arr[i].lost; sort(arr, arr + n, cmp); for(int i = 0; i < n; ++i) printf("%s %d\n", arr[i].name, arr[i].points); printf("\n"); } return 0; }
HDU1225 Football Score 【结构体排序】,布布扣,bubuko.com
HDU1225 Football Score 【结构体排序】
标签:hdu1225
原文地址:http://blog.csdn.net/chang_mu/article/details/26139493