hdoj 1225 football sorce(尝试了50次的水题)
生活随笔
收集整理的這篇文章主要介紹了
hdoj 1225 football sorce(尝试了50次的水题)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
思路:簡單題,細節很多;直接給代碼;
#include <iostream> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <algorithm> #include <vector> using namespace std; struct node {char name[1010];int win;int lose;int point;}team[1010]; int judge(int a, int b) {if (a>b)return 3;else if (a == b)return 1;elsereturn 0; }bool cmp(node a, node b) {if (a.point == b.point){if ((a.win - a.lose) == (b.win - b.lose)){if (a.win == b.win)return a.name[0] < b.name[0]; //這里就是我被wa了30次的原因。。。。少寫了【0】;elsereturn a.win > b.win;}elsereturn a.win - a.lose>b.win - b.lose;}elsereturn a.point>b.point; } int main() {int n;char team1[1010], team2[1010];int p, q;int i;int x;int t;int z1, z2;while (scanf("%d%*c", &n) != EOF){t = n * (n - 1);x = 0;while (t--){z1 = z2 = -1;scanf("%s VS %s %d:%d", team1, team2, &p, &q);for (i = 0; i < x; i++){if (strcmp(team1, team[i].name) == 0)z1 = i;if (strcmp(team2, team[i].name) == 0)z2 = i;if (z1 != -1 && z2 != -1)break;}if (z1 != -1) //比較字符串的時候也有技巧,我這樣的方法比較簡單好理解,也不容易錯{team[z1].point += judge(p, q);team[z1].win += p;team[z1].lose += q;}if (z2 != -1){team[z2].point += judge(q, p);team[z2].win += q;team[z2].lose += p;}if (z1 == -1){memset(team[x].name, 0, sizeof(team[x].name));team[x].point = 0;team[x].lose = 0;team[x].win = 0;strcpy(team[x].name, team1);team[x].point += judge(p, q);team[x].lose += q;team[x].win += p;x++;}if (z2 == -1){memset(team[x].name, 0, sizeof(team[x].name));team[x].point = 0;team[x].lose = 0;team[x].win = 0;strcpy(team[x].name, team2);team[x].point += judge(q, p);team[x].lose += p;team[x].win += q;x++;}}sort(team, team + x, cmp);for (i = 0; i<x; i++){printf("%s %d\n", team[i].name, team[i].point);}printf("\n");}return 0;}總結
以上是生活随笔為你收集整理的hdoj 1225 football sorce(尝试了50次的水题)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 新手如何入门短视频-今抖云创
- 下一篇: 软件需求管理用例方法 pdf_企业内训“