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
难倒是不难的,就是细节问题太重要了,总是在小地方弄错。注释里标的地方注意一下,AC还是可以的。
代码如下:
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; int num; struct node { char name[55]; int win,lost,net; int grade; }data[1000]; int find (char a[]) { for (int i = 0 ; i < num ; i++) { if (strcmp (a , data[i].name) == 0) return i; } return -1; //查无此人 } bool cmp(node a,node b) { if (a.grade != b.grade) return a.grade > b.grade; else if (a.net != b.net) return a.net > b.net; else if (a.win != b.win) return a.win > b.win; else { int t = strcmp (a.name , b.name); if (t == -1) //字典序 return true; else return false; } } int main() { int n; char name1[55]; char name2[55]; int t1,t2; //比分 while (~scanf ("%d",&n)) { num = 0; memset (data,0,sizeof (data)); int tn = n * (n - 1); char VS[3]; for (int i = 0 ; i < tn ; i++) { scanf ("%s %s %s %d:%d",name1,VS,name2,&t1,&t2); int t = find (name1); if (t == -1) { strcpy (data[num].name , name1); data[num].win = t1; data[num].lost = t2; data[num].net = t1 - t2; if (t1 > t2) data[num].grade = 3; else if (t1 == t2) data[num].grade = 1; num++; } else { data[t].win += t1; data[t].lost += t2; data[t].net += (t1 - t2); if (t1 > t2) data[t].grade += 3; else if (t1 == t2) data[t].grade += 1; } t = find (name2); if (t == -1) { strcpy (data[num].name , name2); data[num].win = t2; data[num].lost = t1; data[num].net = t2 - t1; if (t2 > t1) data[num].grade = 3; else if (t1 == t2) data[num].grade = 1; num++; } else { data[t].win += t2; data[t].lost += t1; data[t].net += (t2 - t1); if (t2 > t1) //这里赋值粘贴时记得别写反了(惨痛的教训) data[t].grade += 3; else if (t1 == t2) data[t].grade += 1; } } sort (data , data + n , cmp); for (int i = 0 ; i < n ; i++) printf ("%s %d\n",data[i].name,data[i].grade); printf ("\n"); //少写个换行符 = = 注意注意 } return 0; }